8 releases
new 0.1.8 | Dec 20, 2024 |
---|---|
0.1.7 | Dec 14, 2024 |
0.1.2 | Nov 27, 2024 |
#315 in Asynchronous
928 downloads per month
19KB
353 lines
async-oneshot-channel
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
andSync
where appropriate - Cancellation support: receivers get
None
if all senders drop
Licensed under the MIT license.
Dependencies
~37KB