mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
move graceful shutdown to a single file
This commit is contained in:
parent
58e8da914e
commit
18eab1fbd3
20
pkg/bbgo/graceful_shutdown.go
Normal file
20
pkg/bbgo/graceful_shutdown.go
Normal file
|
@ -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()
|
||||
}
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user