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.


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

assert_eq!(*receiver.latest(), 12);



An error returned from the Updater::update function. Indicates that the paired Receiver has been dropped.


The receiving-half of the single value channel.


The updating-half of the single value channel.



Constructs a single value channel. Initial calls to Receiver::latest will return None.


Constructs a single value channel with an initial value. Thus initial calls to Receiver::latest will return that value until a Updater::update call replaces the latest value.