mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
add IsolationContext
This commit is contained in:
parent
77ca1a9c75
commit
a940e88016
|
@ -1,18 +0,0 @@
|
|||
// Code generated by "callbackgen -type Graceful"; DO NOT EDIT.
|
||||
|
||||
package bbgo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func (g *Graceful) OnShutdown(cb ShutdownHandler) {
|
||||
g.shutdownCallbacks = append(g.shutdownCallbacks, cb)
|
||||
}
|
||||
|
||||
func (g *Graceful) EmitShutdown(ctx context.Context, wg *sync.WaitGroup) {
|
||||
for _, cb := range g.shutdownCallbacks {
|
||||
cb(ctx, wg)
|
||||
}
|
||||
}
|
|
@ -8,17 +8,17 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var graceful = &Graceful{}
|
||||
|
||||
type ShutdownHandler func(ctx context.Context, wg *sync.WaitGroup)
|
||||
|
||||
//go:generate callbackgen -type Graceful
|
||||
type Graceful struct {
|
||||
var graceful = &GracefulShutdown{}
|
||||
|
||||
//go:generate callbackgen -type GracefulShutdown
|
||||
type GracefulShutdown struct {
|
||||
shutdownCallbacks []ShutdownHandler
|
||||
}
|
||||
|
||||
// Shutdown is a blocking call to emit all shutdown callbacks at the same time.
|
||||
func (g *Graceful) Shutdown(ctx context.Context) {
|
||||
func (g *GracefulShutdown) Shutdown(ctx context.Context) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(g.shutdownCallbacks))
|
||||
|
||||
|
|
18
pkg/bbgo/gracefulshutdown_callbacks.go
Normal file
18
pkg/bbgo/gracefulshutdown_callbacks.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Code generated by "callbackgen -type GracefulShutdown"; DO NOT EDIT.
|
||||
|
||||
package bbgo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func (g *GracefulShutdown) OnShutdown(cb ShutdownHandler) {
|
||||
g.shutdownCallbacks = append(g.shutdownCallbacks, cb)
|
||||
}
|
||||
|
||||
func (g *GracefulShutdown) EmitShutdown(ctx context.Context, wg *sync.WaitGroup) {
|
||||
for _, cb := range g.shutdownCallbacks {
|
||||
cb(ctx, wg)
|
||||
}
|
||||
}
|
15
pkg/bbgo/isolation.go
Normal file
15
pkg/bbgo/isolation.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package bbgo
|
||||
|
||||
var currentIsolationContext *IsolationContext
|
||||
|
||||
func init() {
|
||||
currentIsolationContext = NewIsolationContext()
|
||||
}
|
||||
|
||||
type IsolationContext struct {
|
||||
gracefulShutdown GracefulShutdown
|
||||
}
|
||||
|
||||
func NewIsolationContext() *IsolationContext {
|
||||
return &IsolationContext{}
|
||||
}
|
|
@ -89,7 +89,7 @@ type Trader struct {
|
|||
exchangeStrategies map[string][]SingleExchangeStrategy
|
||||
|
||||
// graceful shutdown handlers
|
||||
gracefulShutdown Graceful
|
||||
gracefulShutdown GracefulShutdown
|
||||
|
||||
logger Logger
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user