#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

#317 in Concurrency

Download history 81/week @ 2023-11-29 47/week @ 2023-12-06 74/week @ 2023-12-13 38/week @ 2023-12-20 12/week @ 2023-12-27 20/week @ 2024-01-03 73/week @ 2024-01-10 82/week @ 2024-01-17 40/week @ 2024-01-24 9/week @ 2024-01-31 18/week @ 2024-02-07 43/week @ 2024-02-14 69/week @ 2024-02-21 75/week @ 2024-02-28 91/week @ 2024-03-06 54/week @ 2024-03-13

299 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