bbgo_origin/pkg/bbgo/isolation.go

31 lines
589 B
Go
Raw Normal View History

2022-10-02 11:34:52 +00:00
package bbgo
2022-10-03 08:01:08 +00:00
import (
"context"
)
const IsolationContextKey = "bbgo"
var defaultIsolation = NewIsolation()
2022-10-02 11:34:52 +00:00
type Isolation struct {
2022-10-02 11:34:52 +00:00
gracefulShutdown GracefulShutdown
}
func NewIsolation() *Isolation {
return &Isolation{}
2022-10-02 11:34:52 +00:00
}
2022-10-03 08:01:08 +00:00
func NewIsolationFromContext(ctx context.Context) *Isolation {
isolatedContext, ok := ctx.Value(IsolationContextKey).(*Isolation)
2022-10-03 08:01:08 +00:00
if ok {
return isolatedContext
}
return defaultIsolation
2022-10-03 08:01:08 +00:00
}
func NewContextWithIsolation(parent context.Context, isolation *Isolation) context.Context {
return context.WithValue(parent, IsolationContextKey, isolation)
}