Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithParents ¶
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.