ctxext

package
v0.0.0-...-d14ea06 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2015 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithParents

func WithParents(ctxts ...context.Context) context.Context

WithParents returns a Context that listens to all given parents. It effectively transforms the Context Tree into a Directed Acyclic Graph. This is useful when a context may be cancelled for more than one reason. For example, consider a database with the following Get function:

func (db *DB) Get(ctx context.Context, ...) {}

DB.Get may have to stop for two different contexts:

  • the caller's context (caller might cancel)
  • the database's context (might be shut down mid-request)

WithParents saves the day by allowing us to "merge" contexts and continue on our merry contextual way:

ctx = ctxext.WithParents(ctx, db.ctx)

Passing related (mutually derived) contexts to WithParents is actually ok. The child is cancelled when any of its parents is cancelled, so if any of its parents are also related, the cancel propagation will reach the child via the shortest path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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