bbgo: remove context suffix from the isolation struct

This commit is contained in:
c9s 2022-10-03 16:22:41 +08:00
parent 59287b5116
commit 315f7da8f4
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 9 additions and 9 deletions

View File

@ -41,6 +41,6 @@ func Shutdown(ctx context.Context) {
todo := context.WithValue(context.TODO(), IsolationContextKey, isolatedContext) todo := context.WithValue(context.TODO(), IsolationContextKey, isolatedContext)
timeoutCtx, cancel := context.WithTimeout(todo, 30*time.Second) timeoutCtx, cancel := context.WithTimeout(todo, 30*time.Second)
defaultIsolationContext.gracefulShutdown.Shutdown(timeoutCtx) defaultIsolation.gracefulShutdown.Shutdown(timeoutCtx)
cancel() cancel()
} }

View File

@ -6,25 +6,25 @@ import (
const IsolationContextKey = "bbgo" const IsolationContextKey = "bbgo"
var defaultIsolationContext *IsolationContext = nil var defaultIsolation *Isolation = nil
func init() { func init() {
defaultIsolationContext = NewIsolation() defaultIsolation = NewIsolation()
} }
type IsolationContext struct { type Isolation struct {
gracefulShutdown GracefulShutdown gracefulShutdown GracefulShutdown
} }
func NewIsolation() *IsolationContext { func NewIsolation() *Isolation {
return &IsolationContext{} return &Isolation{}
} }
func NewIsolationFromContext(ctx context.Context) *IsolationContext { func NewIsolationFromContext(ctx context.Context) *Isolation {
isolatedContext, ok := ctx.Value(IsolationContextKey).(*IsolationContext) isolatedContext, ok := ctx.Value(IsolationContextKey).(*Isolation)
if ok { if ok {
return isolatedContext return isolatedContext
} }
return defaultIsolationContext return defaultIsolation
} }