#oneshot-channel #send #async #operation #sender #receiver #value

async-oneshot-channel

A simple async oneshot channel implementation

8 releases

new 0.1.8 Dec 20, 2024
0.1.7 Dec 14, 2024
0.1.2 Nov 27, 2024

#315 in Asynchronous

Download history 347/week @ 2024-11-21 93/week @ 2024-11-28 2/week @ 2024-12-05 486/week @ 2024-12-12

928 downloads per month

MIT license

19KB
353 lines

async-oneshot-channel

License Cargo Documentation

A simple (<100 LoC) "oneshot" channel for asynchronously sending a single value between tasks, in a thread-safe and async-runtime-agnostic manner. This implementation supports cloned senders while ensuring only one send operation will succeed.

Usage

use futures::executor::block_on;

// Create a new channel
let (tx, rx) = oneshot();

// Send a value
tx.send(42).unwrap();

// Receive the value asynchronously
let result = block_on(rx.recv());
assert_eq!(result, Some(42));

Features

  • Multiple senders (through cloning) with guaranteed single-use semantics
  • Async support for receiver, instant send.
  • Thread-safe: implements Send and Sync where appropriate
  • Cancellation support: receivers get None if all senders drop

Licensed under the MIT license.

Dependencies

~37KB