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

async-oneshot-channel

A simple async oneshot channel implementation

8 releases

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

#369 in Asynchronous

Download history 267/week @ 2024-11-20 173/week @ 2024-11-27 2/week @ 2024-12-04 497/week @ 2024-12-11 156/week @ 2024-12-18 2/week @ 2024-12-25 5/week @ 2025-01-08

174 downloads per month
Used in async-actor

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