async-oneshot-channel

Crates.ioasync-oneshot-channel
lib.rsasync-oneshot-channel
version0.1.3
sourcesrc
created_at2024-11-21 01:06:10.220593
updated_at2024-12-12 03:32:26.369665
descriptionA simple async oneshot channel implementation
homepage
repositoryhttps://github.com/AmitPr/async-oneshot-channel
max_upload_size
id1455517
size18,992
Amit Prasad (AmitPr)

documentation

README

async-oneshot-channel

License Cargo Documentation

A simple (<150 LoC, dependency-free) "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.
  • Zero unsafe code in the public API, one unsafe line enforcing MaybeUninit safety.
  • Thread-safe: implements Send and Sync where appropriate
  • Cancellation support: receivers get None if all senders drop

Licensed under the MIT license.

Commit count: 15

cargo fmt