context

package
v0.0.0-...-9a5ce3e Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Std

func Std(ctx Context) context_.Context

Std returns a standard library context from an async one.

Types

type Callback

type Callback interface {
	// OnCancelled is called when the context is cancelled.
	OnCancelled(status.Status)
}

Callback is called when the context is cancelled.

type CancelContext

type CancelContext interface {
	Context

	// Cancel cancels the context.
	Cancel()
}

CancelContext is a cancellable async context.

func Cancelled

func Cancelled() CancelContext

Cancelled returns a cancelled context.

func New

func New() CancelContext

New returns a new cancellable context.

func Next

func Next(parent Context) CancelContext

Next returns a child context.

type Context

type Context interface {
	// Done returns true if the context is cancelled.
	Done() bool

	// Wait returns a channel which is closed when the context is cancelled.
	Wait() <-chan struct{}

	// Status returns a cancellation status or OK.
	Status() status.Status

	// AddCallback adds a callback.
	AddCallback(c Callback)

	// RemoveCallback removes a callback.
	RemoveCallback(c Callback)

	// Free cancels and releases the context.
	Free()
}

Context is an async cancellation context.

Usage:

ctx := NewContext()
defer ctx.Free()

func Deadline

func Deadline(deadline time.Time) Context

Deadline returns a context with a deadline.

func NextDeadline

func NextDeadline(parent Context, deadline time.Time) Context

NextDeadline returns a child context with a deadline.

func NextTimeout

func NextTimeout(parent Context, timeout time.Duration) Context

NextTimeout returns a child context with a timeout.

func No

func No() Context

No returns a non-cancellable background context.

func Timeout

func Timeout(timeout time.Duration) Context

Timeout returns a context with a timeout.

Jump to

Keyboard shortcuts

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