Skip to content

AmitPr/async-oneshot-channel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Simple async oneshot channel for Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages