channels

package
v0.4.9 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 2 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BufferedPipe

func BufferedPipe[T any](ctx context.Context) (chan<- T, <-chan T)

BufferedPipe is a generic, channel and deque buffered pipe implementation.

func Pipe

func Pipe[T any](ctx context.Context, inC <-chan T, outC chan<- T) bool

Pipe is a context aware fused Receive and Submit operation. The function will attempt to receive from the passed readable channel and then submit it to the writable channel. If the context expires during either of these operations this function will return false.

func PipeAll

func PipeAll[T any](ctx context.Context, inC <-chan T, outC chan<- T)

PipeAll is a convenience function that exhausts the passed readable channel by piping the received values to passed writable channel.

func Pipeline

func Pipeline[R any, T any](ctx context.Context, inC <-chan R, outC chan<- T, convertor func(raw R) (T, error)) (bool, error)

Pipeline is a function that operates similarly to a Pipe but allows conversion from the readable channel's type: R to the writable channel's type: T through a passed convertor delegate. Errors from the convertor delegate are returned to the caller.

Conversion failure will result in a receive from the readable channel without a corresponding submit to the writable channel.

func PipelineAll

func PipelineAll[R any, T any](ctx context.Context, inC <-chan R, outC chan<- T, convertor func(raw R) (T, error)) error

PipelineAll is a convenience function that exhausts the passed readable channel by pipelining the received values to the passed writable channel.

func Receive

func Receive[T any](ctx context.Context, inC <-chan T) (T, bool)

Receive takes a valid context.Context, a readable channel and attempts to receive a new value from it. If the function successfully receives the value before the context expires, this function will return both the value and true. If, however the context expires before the function can receive from the channel, or if the channel is closed, this function return false. Both conditions are not explicitly considered errors. It is up to the caller to interpret the return values further.

func Submit

func Submit[T any](ctx context.Context, channel chan<- T, value T) bool

Submit takes a valid context.Context, a writeable channel and attempts to submit the passed value to it. If the function successfully submits the value before the context expires, this function will return true. If, however the context expires before the function can submit to the channel this function return false. Context expiration is not explicitly considered an error. It is up to the caller to interpret the return value further.

Types

type ConcurrencyLimiter

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

func NewConcurrencyLimiter

func NewConcurrencyLimiter(numSlots int) ConcurrencyLimiter

func (ConcurrencyLimiter) Acquire

func (s ConcurrencyLimiter) Acquire(ctx context.Context) bool

func (ConcurrencyLimiter) Release

func (s ConcurrencyLimiter) Release()

Jump to

Keyboard shortcuts

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