Documentation
¶
Index ¶
- func SpawnChild(ctx context.Context) (context.Context, context.CancelFunc)
- func SpawnChildWithTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
- type AppContext
- func (ac *AppContext) Done(ctx context.Context)
- func (ac *AppContext) Get() context.Context
- func (ac *AppContext) Init() context.Context
- func (ac *AppContext) NewChildContext() (context.Context, context.CancelFunc)
- func (ac *AppContext) NewChildContextWithTimeout(timeout time.Duration) (context.Context, context.CancelFunc)
- func (ac *AppContext) SetAppName(app string)
- func (ac *AppContext) Shutdown()
- type ContextInterface
- type GlobalContext
- func (gc *GlobalContext) Done(ctx context.Context)
- func (gc *GlobalContext) Get() context.Context
- func (gc *GlobalContext) Init() context.Context
- func (gc *GlobalContext) ListActiveApps() []string
- func (gc *GlobalContext) NewChildContext() (context.Context, context.CancelFunc)
- func (gc *GlobalContext) NewChildContextWithTimeout(timeout time.Duration) (context.Context, context.CancelFunc)
- func (gc *GlobalContext) SetAppName(app string)
- func (gc *GlobalContext) Shutdown()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SpawnChild ¶
Spawn Child for the given context
func SpawnChildWithTimeout ¶
func SpawnChildWithTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
Spawn Child for the given context with timeout
Types ¶
type AppContext ¶
type AppContext struct {
GlobalContext *GlobalContext
App string
}
func (*AppContext) Done ¶
func (ac *AppContext) Done(ctx context.Context)
func (*AppContext) Get ¶
func (ac *AppContext) Get() context.Context
GetApp returns the app-level context for the current app, initializing it if needed.
func (*AppContext) Init ¶
func (ac *AppContext) Init() context.Context
InitApp initializes an app-level context as a child of the global context. If an app context already exists for this app name, it returns the existing one.
func (*AppContext) NewChildContext ¶
func (ac *AppContext) NewChildContext() (context.Context, context.CancelFunc)
NewChildContextForApp creates a child context derived from the app-level context.
func (*AppContext) NewChildContextWithTimeout ¶
func (ac *AppContext) NewChildContextWithTimeout(timeout time.Duration) (context.Context, context.CancelFunc)
NewChildContextForAppWithTimeout creates a child context with timeout from the app-level context.
func (*AppContext) SetAppName ¶
func (ac *AppContext) SetAppName(app string)
SetAppName sets the name of the app for the app context.
func (*AppContext) Shutdown ¶
func (ac *AppContext) Shutdown()
ShutdownApp cancels the app-level context for the current app.
type ContextInterface ¶
type ContextInterface interface {
Init() context.Context
Get() context.Context
Shutdown()
Done(ctx context.Context)
NewChildContext() (context.Context, context.CancelFunc)
NewChildContextWithTimeout(timeout time.Duration) (context.Context, context.CancelFunc)
SetAppName(app string)
}
func GetAppContext ¶
func GetAppContext(app string) ContextInterface
func GetGlobalContext ¶
func GetGlobalContext() ContextInterface
type GlobalContext ¶
type GlobalContext struct{}
func (*GlobalContext) Done ¶
func (gc *GlobalContext) Done(ctx context.Context)
func (*GlobalContext) Get ¶
func (gc *GlobalContext) Get() context.Context
Get returns the currently initialized global context, calling Init if needed so callers can always rely on a valid parent context.
func (*GlobalContext) Init ¶
func (gc *GlobalContext) Init() context.Context
Init sets up the global context if it hasn't been created yet and returns it so callers can use it as a parent.
func (*GlobalContext) ListActiveApps ¶
func (gc *GlobalContext) ListActiveApps() []string
ListActiveApps returns a list of all apps with active contexts.
func (*GlobalContext) NewChildContext ¶
func (gc *GlobalContext) NewChildContext() (context.Context, context.CancelFunc)
NewChildContext creates a child context derived from the global context.
func (*GlobalContext) NewChildContextWithTimeout ¶
func (gc *GlobalContext) NewChildContextWithTimeout(timeout time.Duration) (context.Context, context.CancelFunc)
NewChildContextWithTimeout creates a child context with timeout from the global context.
func (*GlobalContext) SetAppName ¶
func (gc *GlobalContext) SetAppName(app string)
SetAppName is a no-op for GlobalContext since it doesn't have an app name.
func (*GlobalContext) Shutdown ¶
func (gc *GlobalContext) Shutdown()
Shutdown triggers the cancellation of the global context and all app-level contexts.