move graceful shutdown to a single file

This commit is contained in:
c9s 2022-05-05 09:56:21 +08:00
parent 58e8da914e
commit 18eab1fbd3
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 20 additions and 15 deletions

View 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()
}

View File

@ -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()