#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

#387 in Concurrency

Download history 135/week @ 2023-11-06 169/week @ 2023-11-13 112/week @ 2023-11-20 132/week @ 2023-11-27 90/week @ 2023-12-04 127/week @ 2023-12-11 91/week @ 2023-12-18 66/week @ 2023-12-25 48/week @ 2024-01-01 126/week @ 2024-01-08 92/week @ 2024-01-15 128/week @ 2024-01-22 51/week @ 2024-01-29 57/week @ 2024-02-05 85/week @ 2024-02-12 213/week @ 2024-02-19

406 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