Documentation
¶
Overview ¶
Package safechan provides safe channel utilities for Go.
It offers panic-free send operations, context-aware channel communication, and channel combinators such as fan-in, fan-out, and broadcast.
Index ¶
- func Broadcast[T any](ch <-chan T, n int) []<-chan T
- func FanIn[T any](channels ...<-chan T) <-chan T
- func FanOut[T any](ch <-chan T, n int) []<-chan T
- func Recv[T any](ch <-chan T) (val T, ok bool)
- func RecvCtx[T any](ctx context.Context, ch <-chan T) (val T, ok bool)
- func Send[T any](ch chan<- T, val T) (sent bool)
- func SendCtx[T any](ctx context.Context, ch chan<- T, val T) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Broadcast ¶
Broadcast sends each value from the input channel to all n output channels. Every output channel receives every value. All output channels are closed when the input channel is closed.
func FanIn ¶
func FanIn[T any](channels ...<-chan T) <-chan T
FanIn merges multiple input channels into a single output channel. The output channel is closed when all input channels have been closed. Values are forwarded as they arrive from any input channel.
func FanOut ¶
FanOut distributes values from a single input channel to n output channels in a round-robin fashion. All output channels are closed when the input channel is closed.
func Recv ¶
Recv receives a value from ch. It returns the value and true if a value was received, or the zero value and false if the channel is closed. This is a thin wrapper around the built-in receive for API consistency.
func RecvCtx ¶
RecvCtx receives a value from ch, respecting context cancellation. It returns the value and true if a value was received, or the zero value and false if the context was done or the channel is closed.
Types ¶
This section is empty.