context

package module
v0.0.0-...-9835c42 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2017 License: Apache-2.0 Imports: 3 Imported by: 6

README

context

Drop in replacement for Go's Context with support for waiting on children.

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

View Source
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

func EnableWait(ctx Context) Context

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.

func TODO

func TODO() Context

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL