ChannelProtocol

public protocol ChannelProtocol

A protocol that defines primitives for unidirectional communication between a sender and a receiver task. The sending side of a channel is convertible to a sink and the receiving to a stream.

Channels are categorized into different flavors based on whether they support a single or multiple senders and whether they apply backpressure when their internal buffer reaches a configurable limit.

Channels can be explicitly closed by either the sending or receiving side. Dropping either side causes the channel to close automatically. Senders are prevented from sending new items into a closed channel. Any items buffered by the channel, however, can still be taken out by the receiver.

Senders can request to be notified when the channel is flushed. Flushing is not an exclusive operation; other senders are not prevented from sending an item, or even closing the channel. Therefore flushing is useful primarily with single-sender channels. Flushing multi-sender channels is less reliable because of the indeterminism inherent in that configuration – a sender may request a flush and by the time it returns to check that flushing completed another sender running on another thread might have sent a new item. You have to externally coordinate the senders in this case.