Categorygithub.com/eapache/channels
modulepackage
1.1.0
Repository: https://github.com/eapache/channels.git
Documentation: pkg.go.dev

# README

channels

Build Status GoDoc Code of Conduct

A collection of helper functions and special types for working with and extending Go's existing channels. Due to limitations of Go's type system, importing this library directly is often not practical for production code. It serves equally well, however, as a reference guide and template for implementing many common idioms; if you use it in this way I would appreciate the inclusion of some sort of credit in the resulting code.

See https://godoc.org/github.com/eapache/channels for full documentation or https://gopkg.in/eapache/channels.v1 for a versioned import path.

Requires Go version 1.1 or later, as certain necessary elements of the reflect package were not present in 1.0.

Most of the buffered channel types in this package are backed by a very fast queue implementation that used to be built into this package but has now been extracted into its own package at https://github.com/eapache/queue.

Note: Several types in this package provide so-called "infinite" buffers. Be very careful using these, as no buffer is truly infinite. If such a buffer grows too large your program will run out of memory and crash. Caveat emptor.

# Functions

Distribute takes a single input channel and an arbitrary number of output channels and duplicates each input into *one* available output.
Multiplex takes an arbitrary number of input channels and multiplexes their output into a single output channel.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewNativeChannel makes a new NativeChannel with the given buffer size.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Pipe connects the input channel to the output channel so that they behave as if a single channel.
Tee (like its Unix namesake) takes a single input channel and an arbitrary number of output channels and duplicates each input into every output.
Unwrap takes a SimpleOutChannel and uses reflection to pipe it to a typed native channel for easy integration with existing channel sources.
WeakDistribute behaves like Distribute (distributing a single input amongst multiple outputs) except that it does not close the output channels when the input channel is closed.
WeakMultiplex behaves like Multiplex (multiplexing multiple inputs into a single output) except that it does not close the output channel when the input channels are closed.
WeakPipe behaves like Pipe (connecting the two channels) except that it does not close the output channel when the input channel is closed.
WeakTee behaves like Tee (duplicating a single input into multiple outputs) except that it does not close the output channels when the input channel is closed.
Wrap takes any readable channel type (chan or <-chan but not chan<-) and exposes it as a SimpleOutChannel for easy integration with existing channel sources.

# Constants

Infinity is the capacity for channels with no limit on their buffer size.
None is the capacity for channels that have no buffer at all.

# Structs

BatchingChannel implements the Channel interface, with the change that instead of producing individual elements on Out(), it batches together the entire internal buffer each time.
BlackHole implements the InChannel interface and provides an analogue for the "Discard" variable in the ioutil package - it never blocks, and simply discards every value it reads.
DeadChannel is a placeholder implementation of the Channel interface with no buffer that is never ready for reading or writing.
InfiniteChannel implements the Channel interface with an infinite buffer between the input and the output.
OverflowingChannel implements the Channel interface in a way that never blocks the writer.
ResizableChannel implements the Channel interface with a resizable buffer between the input and the output.
RingChannel implements the Channel interface in a way that never blocks the writer.
SharedBuffer implements the Buffer interface, and permits multiple SimpleChannel instances to "share" a single buffer.Each channel spawned by NewChannel has its own internal queue (so values flowing through do not get mixed up withother channels) but the total number of elements buffered by all spawned channels is limited to a single capacity.

# Interfaces

Buffer is an interface for any channel that provides access to query the state of its buffer.
Channel is an interface representing a channel that is readable, writeable and implements the Buffer interface.
InChannel is an interface representing a writeable channel with a buffer.
OutChannel is an interface representing a readable channel implementing the Buffer interface.
SimpleChannel is an interface representing a channel that is both readable and writeable, but does not necessarily implement the Buffer interface.
SimpleInChannel is an interface representing a writeable channel that does not necessarily implement the Buffer interface.
SimpleOutChannel is an interface representing a readable channel that does not necessarily implement the Buffer interface.

# Type aliases

BufferCap represents the capacity of the buffer backing a channel.