Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChanContext ¶
ChanContext is a wrapper around a channel that binds it to a context.
func NewChanContext ¶
func NewChanContext[T any](ctx context.Context, buffer int) ChanContext[T]
NewChanContext creates a new ChanContext instance.
func (ChanContext[T]) Recv ¶
func (cc ChanContext[T]) Recv() (v T, ok bool)
Recv receives a value from the channel. If the context is canceled, this method returns immediately with a zero value and false. If the channel is closed, this method returns a zero value and false.
func (ChanContext[T]) Send ¶
func (cc ChanContext[T]) Send(v T) bool
Send sends a value to the channel. If the context is canceled, this method returns immediately with false.
func (ChanContext[T]) SendNonBlocking ¶
func (cc ChanContext[T]) SendNonBlocking(v T) bool
SendNonBlocking sends a value to the channel without blocking. If the context is canceled or the channel is full, this method returns immediately with false.
type FanIn ¶
type FanIn[T any] struct { // contains filtered or unexported fields }
FanIn is a fan-in channel multiplexer. It takes multiple input channels and merges them into a single output channel. The implementation is thread-safe.
func (*FanIn[T]) AutoClose ¶
func (fi *FanIn[T]) AutoClose()
AutoClose will automatically close the output channel when all input channels are closed. This method must be called only after at least one input channel has been added. Otherwise, it will immediately close the output channel. This method is idempotent and non-blocking.
func (*FanIn[T]) Close ¶
func (fi *FanIn[T]) Close()
Close closes the output channel. This method must be called only after all input channels are closed. Otherwise, the code may panic due to sending to a closed channel. To make sure that all input channels are closed, a call to this method can be preceded by a call to the Wait method. Alternatively, the AutoClose method can be used.
type FanOut ¶
type FanOut[T any] struct { // contains filtered or unexported fields }
FanOut is a fan-out channel demultiplexer. It takes a single input channel and distributes its values to multiple output channels. The input channel is emptied even if there are no output channels. Output channels are closed when the input channel is closed. The implementation is thread-safe.
func (*FanOut[T]) Close ¶
func (fo *FanOut[T]) Close(ch <-chan T)
Close stops sending values to the given output channel and closes it.
If the output channel is already closed or it was not created by the Output or OutputContext method, this method does nothing.
func (*FanOut[T]) Output ¶
func (fo *FanOut[T]) Output() <-chan T
Output returns a new output channel.
func (*FanOut[T]) OutputContext ¶
OutputContext returns a new output channel. The channel is closed when the given context is canceled.