contextmanager

package
v0.32.5 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package contextmanager simulates multiple-parent contexts with sticky cancellation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager[K fmt.Stringer] struct {
	// contains filtered or unexported fields
}

Manager tracks contexts derived from the root context.

func New

func New[K fmt.Stringer](root context.Context) *Manager[K]

New creates a new context manager.

func (*Manager[K]) Cancel

func (m *Manager[K]) Cancel(key K, reason error)

Cancel cancels the context for the given key with reason. If no context exists for the key a context will be created and cancelled.

func (*Manager[K]) Context

func (m *Manager[K]) Context(parent context.Context, key K) (context.Context, context.CancelFunc)

Context returns a new context that is derived from parent. The context will be cancelled if either the manager's root context or the respective key context is cancelled.

func (*Manager[K]) Delete

func (m *Manager[K]) Delete(key K, reason error)

Delete removes the entry for the given key, cancelling its context with reason.

func (*Manager[K]) Shutdown

func (m *Manager[K]) Shutdown()

Shutdown cancels the root context, which propagates to all contexts.

Jump to

Keyboard shortcuts

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