bbgo: add NewContextWithIsolation function

This commit is contained in:
c9s 2022-10-03 18:39:07 +08:00
parent f7e76c0518
commit 198683d141
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -6,11 +6,7 @@ import (
const IsolationContextKey = "bbgo" const IsolationContextKey = "bbgo"
var defaultIsolation *Isolation = nil var defaultIsolation = NewIsolation()
func init() {
defaultIsolation = NewIsolation()
}
type Isolation struct { type Isolation struct {
gracefulShutdown GracefulShutdown gracefulShutdown GracefulShutdown
@ -28,3 +24,7 @@ func NewIsolationFromContext(ctx context.Context) *Isolation {
return defaultIsolation return defaultIsolation
} }
func NewContextWithIsolation(parent context.Context, isolation *Isolation) context.Context {
return context.WithValue(parent, IsolationContextKey, isolation)
}