ctxchan

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 1 Imported by: 0 modules, 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 ctxchan provides channel operations that give up when a context is done.

Each operation first checks ctx.Err(), an atomic load, so a call made after ctx is done leaves the channel alone even if it is ready. It then tries a non-blocking send or receive, which costs a fraction of a select, and falls back to selecting on the channel and ctx.Done() only when it would block. A context that can never be done, such as context.Background(), gets a plain send or receive.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Recv

func Recv[T any](ctx context.Context, in <-chan T) (v T, ok bool, err error)

Recv receives a value from in, like v, ok := <-in, unless ctx is done: then it returns ctx.Err() and v and ok are meaningless.

func Send

func Send[T any](ctx context.Context, ch chan<- T, v T) error

Send sends v on ch, unless ctx is done: then it returns ctx.Err().

Types

This section is empty.

Jump to

Keyboard shortcuts

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