chanutil

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOutputClosed = errors.New("output channel closed")

Functions

This section is empty.

Types

type FanIn added in v0.9.0

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 NewFanIn added in v0.9.0

func NewFanIn[T any](chs ...<-chan T) *FanIn[T]

NewFanIn creates a new FanIn instance.

func (*FanIn[T]) Add added in v0.9.0

func (fi *FanIn[T]) Add(chs ...<-chan T) error

Add adds a new input channel. If the output channel is already closed, the error is returned.

func (*FanIn[T]) AutoClose added in v0.9.0

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 added in v0.9.0

func (fi *FanIn[T]) Chan() <-chan T

Chan returns the output channel.

func (*FanIn[T]) Close added in v0.9.0

func (fi *FanIn[T]) Close() error

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.

func (*FanIn[T]) Wait added in v0.9.0

func (fi *FanIn[T]) Wait()

Wait blocks until all the input channels are closed.

type FanOut added in v0.9.0

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 NewFanOut added in v0.9.0

func NewFanOut[T any](ch chan T) *FanOut[T]

NewFanOut creates a new FanOut instance.

func (*FanOut[T]) Chan added in v0.9.0

func (fo *FanOut[T]) Chan() <-chan T

Chan returns a new output channel.

Jump to

Keyboard shortcuts

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