mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 15:10:54 +00:00
Feature: Faster start & stop times (#648)
* Updates starting and stopping routines to be a bit more parallel with less waiting required * Removes stop, removes debugging output * linting and test fixes * Add extra kill switch for exiting on exchange loading delay * Fixes fun math * breaks loop instead of switch. Moves param warns higher * Removes unceccary gos. passes in cfg to remove data race * Removes os signal processing. Fixes bad master merge
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/connchecker"
|
||||
"github.com/thrasher-corp/gocryptotrader/engine/subsystem"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
)
|
||||
|
||||
// connectionManager manages the connchecker
|
||||
type connectionManager struct {
|
||||
started int32
|
||||
stopped int32
|
||||
conn *connchecker.Checker
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ func (c *connectionManager) Started() bool {
|
||||
|
||||
// Start starts an instance of the connection manager
|
||||
func (c *connectionManager) Start(conf *config.ConnectionMonitorConfig) error {
|
||||
if atomic.AddInt32(&c.started, 1) != 1 {
|
||||
return errors.New("connection manager already started")
|
||||
if !atomic.CompareAndSwapInt32(&c.started, 0, 1) {
|
||||
return fmt.Errorf("connection manager %w", subsystem.ErrSubSystemAlreadyStarted)
|
||||
}
|
||||
|
||||
log.Debugln(log.ConnectionMgr, "Connection manager starting...")
|
||||
@@ -44,17 +44,14 @@ func (c *connectionManager) Start(conf *config.ConnectionMonitorConfig) error {
|
||||
// Stop stops the connection manager
|
||||
func (c *connectionManager) Stop() error {
|
||||
if atomic.LoadInt32(&c.started) == 0 {
|
||||
return errors.New("connection manager not started")
|
||||
}
|
||||
|
||||
if atomic.AddInt32(&c.stopped, 1) != 1 {
|
||||
return errors.New("connection manager is already stopped")
|
||||
return fmt.Errorf("connection manager %w", subsystem.ErrSubSystemNotStarted)
|
||||
}
|
||||
defer func() {
|
||||
atomic.CompareAndSwapInt32(&c.started, 1, 0)
|
||||
}()
|
||||
|
||||
log.Debugln(log.ConnectionMgr, "Connection manager shutting down...")
|
||||
c.conn.Shutdown()
|
||||
atomic.CompareAndSwapInt32(&c.stopped, 1, 0)
|
||||
atomic.CompareAndSwapInt32(&c.started, 1, 0)
|
||||
log.Debugln(log.ConnectionMgr, "Connection manager stopped.")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user