[][src]Crate update_channel

Single value multiple producer multiple consumer update channel. Both the receiver and channel can be created with the update_channel and update_channel_with functions.

The channels are mostly lock free, multiple readers can access the shared value at the same time. The only way to really block is by calling the borrow_locked method and holding onto the RwLockReadGuard or by having a lot of writes happen at the same time.

The update channel can practically be seen as a single value which can be updated by an updater and then a receiver can update its own internal value with the receive_update method by cloning the new value in its internal buffer. If only a single receiver is used the take_update method is a more efficient alternative to the receive_update method


use update_channel::channel_with;
use std::thread::spawn;
let (mut receiver, updater) = channel_with(0);
assert_eq!(*receiver.borrow(), 0);
spawn(move || {
    updater.update(2).unwrap(); // shared value is 2
    updater.update(12).unwrap(); // shared value is 12
// Shared value is 2 but internal value is 0
assert_eq!(*receiver.borrow(), 0);
// Update the latest value
// Shared value is 12 and internal value 12
assert_eq!(*receiver.borrow(), 12);



An error that might occur while receiving a value


The receiving half of an update channel


The updater half of the update channel.



An error occurred while updating the update channel



Creates a channel with None as start value


Starts the channel with the default value of T


Create a channel where the receiver starts with value as internal value