Documentation ¶
Overview ¶
Package fscontext contains helpers for migrating Fleetspeak to context.Context.
Fleetspeak should better use context.Context for cancelation than chan struct{}s.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrStopRequested = fmt.Errorf("%w: stop requested", context.Canceled)
ErrStopRequested is the cancelation cause to be used when callers intentionally cancel a context from the outside.
Functions ¶
func WithDoneChan ¶
func WithDoneChan(ctx context.Context, cause error, done <-chan struct{}) (newCtx context.Context, cancel context.CancelCauseFunc)
WithDoneChan returns a new context and cancel function.
The context is automatically canceled with the given cause as soon as done is closed.
This is not meant as a long-term solution, but as a migration path for code which has a "done" channel but which needs to provide a context.
Callers must always call cancel after the context is done.
Example usage:
errDoneClosed := fmt.Errorf("my magic done channel was closed: %w", fscontext.ErrStopRequested) ctx, cancel := fscontext.WithDoneChan(ctx, errDoneClosed, xyz.done) defer cancel(nil)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.