#channel #value #update #single #non-blocking #latest

single_value_channel

Concurrent single-value update and receive channel

5 stable releases

1.2.2 Feb 21, 2021
1.2.1 Aug 26, 2019
1.2.0 Apr 4, 2019
1.1.0 Jun 29, 2017
1.0.0 Jun 21, 2017

#398 in Concurrency

Download history 67/week @ 2024-03-14 80/week @ 2024-03-21 121/week @ 2024-03-28 98/week @ 2024-04-04 87/week @ 2024-04-11 83/week @ 2024-04-18 111/week @ 2024-04-25 129/week @ 2024-05-02 55/week @ 2024-05-09 62/week @ 2024-05-16 49/week @ 2024-05-23 50/week @ 2024-05-30 50/week @ 2024-06-06 77/week @ 2024-06-13 156/week @ 2024-06-20 205/week @ 2024-06-27

492 downloads per month
Used in 4 crates

Apache-2.0

13KB
212 lines

single_value_channel crates.io Documentation

Non-blocking 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. See the documentation for more details.

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);

Minimum supported rust compiler

This crate is maintained with latest stable rust.

No runtime deps