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.
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));- Multiple senders (through cloning) with guaranteed single-use semantics
- Async support for receiver, instant send.
- Thread-safe: implements
SendandSyncwhere appropriate - Cancellation support: receivers get
Noneif all senders drop
Licensed under the MIT license.