diff --git a/pkg/bbgo/isolation.go b/pkg/bbgo/isolation.go index 1f11d6be6..8d1f50f48 100644 --- a/pkg/bbgo/isolation.go +++ b/pkg/bbgo/isolation.go @@ -6,11 +6,7 @@ import ( const IsolationContextKey = "bbgo" -var defaultIsolation *Isolation = nil - -func init() { - defaultIsolation = NewIsolation() -} +var defaultIsolation = NewIsolation() type Isolation struct { gracefulShutdown GracefulShutdown @@ -28,3 +24,7 @@ func NewIsolationFromContext(ctx context.Context) *Isolation { return defaultIsolation } + +func NewContextWithIsolation(parent context.Context, isolation *Isolation) context.Context { + return context.WithValue(parent, IsolationContextKey, isolation) +}