Skip to main content

Module mpsc

Module mpsc 

Source
Expand description

Multi-producer, single-consumer channels for the tasks of one shard.

The names, signatures and error types follow sync::mpsc, so code switches by changing the path. The state sits in one Rc and plain cells, so the halves are !Send and no operation touches an atomic.

The bounded flavor (channel) holds at most a fixed number of messages and serves waiting sends strictly in arrival order; the unbounded one (unbounded_channel) never makes a send wait.

What one sender sends comes out in the order it was sent. When every sender is dropped the stream ends: once the buffered values are received, recv returns None. If the receiver is dropped, its unread values are dropped with it and every later send fails with an error that holds the value; Receiver::close first stops further sends and keeps the buffered values, and the slots reserved before it, usable.

Left out, because a local channel never leaves its thread: the blocking_* methods (a blocking call there could only wait for itself) and WeakSender.

Receives, and sends that complete at their first attempt, spend the cooperative budget (see task::coop) as the atomic channels do.

Structs§

Permit
Room for one message, reserved before the message exists.
Receiver
Receives values from the associated Senders.
Sender
Sends values to the associated Receiver.
UnboundedReceiver
Receives values from the associated UnboundedSenders.
UnboundedSender
Sends values to the associated UnboundedReceiver.

Functions§

channel
Creates a bounded channel that holds at most buffer messages, and answers its two halves.
unbounded_channel
Creates an unbounded channel and answers its two halves.