ctxwatch

package
v5.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 2 Imported by: 33 modules, 6 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextWatcher

type ContextWatcher struct {
	// contains filtered or unexported fields
}

ContextWatcher watches a context and performs an action when the context is canceled. It can watch one context at a time.

func NewContextWatcher

func NewContextWatcher(handler Handler) *ContextWatcher

NewContextWatcher returns a ContextWatcher. onCancel will be called when a watched context is canceled. OnUnwatchAfterCancel will be called when Unwatch is called and the watched context had already been canceled and onCancel called.

func (*ContextWatcher) Unwatch

func (cw *ContextWatcher) Unwatch()

Unwatch stops watching the previously watched context. If the onCancel function passed to NewContextWatcher was called then onUnwatchAfterCancel will also be called.

func (*ContextWatcher) Watch

func (cw *ContextWatcher) Watch(ctx context.Context)

Watch starts watching ctx. If ctx is canceled then the onCancel function passed to NewContextWatcher will be called.

type Handler

type Handler interface {
	// HandleCancel is called when the context that a ContextWatcher is currently watching is canceled. canceledCtx is the
	// context that was canceled.
	HandleCancel(canceledCtx context.Context)

	// HandleUnwatchAfterCancel is called when a ContextWatcher that called HandleCancel on this Handler is unwatched.
	HandleUnwatchAfterCancel()
}

Jump to

Keyboard shortcuts

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