From 18eab1fbd39ef8148e9da0bdb5a20ff26ac5373f Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 5 May 2022 09:56:21 +0800 Subject: [PATCH] move graceful shutdown to a single file --- pkg/bbgo/graceful_shutdown.go | 20 ++++++++++++++++++++ pkg/bbgo/trader.go | 15 --------------- 2 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 pkg/bbgo/graceful_shutdown.go diff --git a/pkg/bbgo/graceful_shutdown.go b/pkg/bbgo/graceful_shutdown.go new file mode 100644 index 000000000..b35482ce2 --- /dev/null +++ b/pkg/bbgo/graceful_shutdown.go @@ -0,0 +1,20 @@ +package bbgo + +import ( + "context" + "sync" +) + +//go:generate callbackgen -type Graceful +type Graceful struct { + shutdownCallbacks []func(ctx context.Context, wg *sync.WaitGroup) +} + +func (g *Graceful) Shutdown(ctx context.Context) { + var wg sync.WaitGroup + wg.Add(len(g.shutdownCallbacks)) + + go g.EmitShutdown(ctx, &wg) + + wg.Wait() +} diff --git a/pkg/bbgo/trader.go b/pkg/bbgo/trader.go index c6eefb2c1..110b2831b 100644 --- a/pkg/bbgo/trader.go +++ b/pkg/bbgo/trader.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "reflect" - "sync" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -43,20 +42,6 @@ type Validator interface { Validate() error } -//go:generate callbackgen -type Graceful -type Graceful struct { - shutdownCallbacks []func(ctx context.Context, wg *sync.WaitGroup) -} - -func (g *Graceful) Shutdown(ctx context.Context) { - var wg sync.WaitGroup - wg.Add(len(g.shutdownCallbacks)) - - go g.EmitShutdown(ctx, &wg) - - wg.Wait() -} - type Logging interface { EnableLogging() DisableLogging()