#concurrent #channel

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

#67 in Concurrency

Download history 82/week @ 2020-11-10 22/week @ 2020-11-17 28/week @ 2020-11-24 80/week @ 2020-12-01 19/week @ 2020-12-08 36/week @ 2020-12-15 16/week @ 2020-12-22 57/week @ 2020-12-29 20/week @ 2021-01-05 59/week @ 2021-01-12 50/week @ 2021-01-19 87/week @ 2021-01-26 41/week @ 2021-02-02 105/week @ 2021-02-09 80/week @ 2021-02-16 72/week @ 2021-02-23

216 downloads per month
Used in 2 crates

Apache-2.0

12KB
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