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

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

#472 in Concurrency

Download history 268/week @ 2024-11-15 342/week @ 2024-11-22 327/week @ 2024-11-29 246/week @ 2024-12-06 172/week @ 2024-12-13 87/week @ 2024-12-20 14/week @ 2024-12-27 153/week @ 2025-01-03 236/week @ 2025-01-10 389/week @ 2025-01-17 195/week @ 2025-01-24 329/week @ 2025-01-31 258/week @ 2025-02-07 200/week @ 2025-02-14 121/week @ 2025-02-21 113/week @ 2025-02-28

730 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