mod.rs |
A multi-producer, single-consumer queue for sending values across
asynchronous tasks.
Similarly to the `std`, channel creation provides [`Receiver`] and
[`Sender`] handles. [`Receiver`] implements [`Stream`] and allows a task to
read values out of the channel. If there is no message to read from the
channel, the current task will be notified when a new value is sent.
[`Sender`] implements the `Sink` trait and allows a task to send messages into
the channel. If the channel is at capacity, the send will be rejected and
the task will be notified when additional capacity is available. In other
words, the channel provides backpressure.
Unbounded channels are also available using the `unbounded` constructor.
# Disconnection
When all [`Sender`] handles have been dropped, it is no longer
possible to send values into the channel. This is considered the termination
event of the stream. As such, [`Receiver::poll_next`]
will return `Ok(Ready(None))`.
If the [`Receiver`] handle is dropped, then messages can no longer
be read out of the channel. In this case, all further attempts to send will
result in an error.
# Clean Shutdown
If the [`Receiver`] is simply dropped, then it is possible for
there to be messages still in the channel that will not be processed. As
such, it is usually desirable to perform a "clean" shutdown. To do this, the
receiver will first call `close`, which will prevent any further messages to
be sent into the channel. Then, the receiver consumes the channel to
completion, at which point the receiver can be dropped.
[`Sender`]: struct.Sender.html
[`Receiver`]: struct.Receiver.html
[`Stream`]: ../../futures_core/stream/trait.Stream.html
[`Receiver::poll_next`]:
../../futures_core/stream/trait.Stream.html#tymethod.poll_next |
46214 |
queue.rs |
A mostly lock-free multi-producer, single consumer queue for sending
messages between asynchronous tasks.
The queue implementation is essentially the same one used for mpsc channels
in the standard library.
Note that the current implementation of this queue has a caveat of the `pop`
method, and see the method for more information about it. Due to this
caveat, this queue may not be appropriate for all use-cases. |
6702 |
sink_impl.rs |
|
2315 |