Crate single_value_channel [−] [src]
Single value update and receive channel.
This module provides a latest-message style channel, where update sources can update the latest value that the receiver owns in a practically non-blocking way.
Unlike the mpsc::channel
each value send will overwrite the 'latest' value.
This is useful, for example, when thread A is interested in the latest result of another continually working thread B. B could update the channel with it's latest result each iteration, each new update becoming the new 'latest' value. Then A can access that latest value. Neither the write nor read are blocked by the other thread.
It is practically non-blocking as an updater thread cannot block the receiver thread or vice versa. The internal sync primitives are private and essentially only lock over fast data moves.
Example
use single_value_channel::channel_starting_with; use std::thread; let (mut receiver, updater) = channel_starting_with(0); assert_eq!(*receiver.latest(), 0); thread::spawn(move|| { updater.update(2); // next access to receiver.latest() -> 2 updater.update(12); // next access to receiver.latest() -> 12 }).join(); assert_eq!(*receiver.latest(), 12);
Structs
NoReceiverError |
An error returned from the |
Receiver |
The receiving-half of the single value channel. |
Updater |
The updating-half of the single value channel. |
Functions
channel |
Constructs a single value channel. Initial calls to
|
channel_starting_with |
Constructs a single value channel with an initial value. Thus initial calls to
|