Documentation ¶
Overview ¶
Package context implements a drop-in replacement for the standard library context package. It has all the features of the standard library version plus support for waiting on derived contexts (including supporting functions/methods).
See https://golang.org/pkg/context.
Example usage:
root := context.Background()
workersCtx, cancel := context.WithCancel(root) defer cancel()
for i:=0; i < numWorkers; i++ { go startWorker(context.EnableWait(workersCtx)) }
root.WaitForChildren()
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Errors. Canceled = context.Canceled DeadlineExceeded = context.DeadlineExceeded )
Functions ¶
func WithCancel ¶
func WithCancel(parent Context) (Context, CancelFunc)
func WithDeadline ¶
func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc)
func WithTimeout ¶
func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc)
Types ¶
type CancelFunc ¶
type CancelFunc context.CancelFunc
type Context ¶
type Context interface { context.Context // Finished reports back to the parent Context that the work associated // with this Context has finished. This must be explicitly called when // using the waiting feature. Finished() // Wait waits on all immediate children to finish their work. It blocks // until all children report that their work is finished. WaitForChildren() // contains filtered or unexported methods }
Context behaves exactly like a standard library Context but also includes support for waiting on derived (child) Contexts.
See https://golang.org/pkg/context/#Context.
func Background ¶
func Background() Context
func EnableWait ¶
EnableWait enables waiting on this context completion. When the work associated with this context finishes (ctx.Finished() is called the same number of times that EnableWait() is called), any caller waiting on the parent context will unblock.