contextmanager

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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