Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrOutputClosed = errors.New("output channel closed")
Functions ¶
This section is empty.
Types ¶
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]) Add ¶
Add adds a new input channel. If the output channel is already closed, the error is returned.
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]) Chan ¶
func (fi *FanIn[T]) Chan() <-chan T
Chan returns the output channel.
Because there is only one output channel, this method can be called only once to prevent using the same channel in multiple places which may lead to unexpected results. Calling this method multiple times will panic.
func (*FanIn[T]) Close ¶
Close closes the output channel. If the output channel is already closed, the error is returned. 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.