mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
31 lines
542 B
Go
31 lines
542 B
Go
package bbgo
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const IsolationContextKey = "bbgo"
|
|
|
|
var defaultIsolationContext *IsolationContext = nil
|
|
|
|
func init() {
|
|
defaultIsolationContext = NewIsolation()
|
|
}
|
|
|
|
type IsolationContext struct {
|
|
gracefulShutdown GracefulShutdown
|
|
}
|
|
|
|
func NewIsolation() *IsolationContext {
|
|
return &IsolationContext{}
|
|
}
|
|
|
|
func NewIsolationFromContext(ctx context.Context) *IsolationContext {
|
|
isolatedContext, ok := ctx.Value(IsolationContextKey).(*IsolationContext)
|
|
if ok {
|
|
return isolatedContext
|
|
}
|
|
|
|
return defaultIsolationContext
|
|
}
|