2 releases

0.1.1 Dec 11, 2025
0.1.0 Apr 29, 2025

#1762 in Asynchronous

Download history 699/week @ 2026-02-16 928/week @ 2026-02-23 1173/week @ 2026-03-02 799/week @ 2026-03-09 1062/week @ 2026-03-16 1080/week @ 2026-03-23 857/week @ 2026-03-30 1119/week @ 2026-04-06 1442/week @ 2026-04-13 1630/week @ 2026-04-20 1659/week @ 2026-04-27 1214/week @ 2026-05-04 1333/week @ 2026-05-11 1664/week @ 2026-05-18 1373/week @ 2026-05-25 1400/week @ 2026-06-01

5,834 downloads per month
Used in 5 crates (via async-ssh2-russh)

Apache-2.0

14KB
183 lines

async-promise

A simple promise implementation that allows for a single producer to resolve a value to multiple consumers.

Similar to a oneshot channel, but allows for multiple consumers to wait for the value to be resolved, which will be provided as a reference (&T).

Similar to an async OnceCell, but consumers may only await the value, and may not attempt to set it.

Use [channel()] to create a new promise and resolver pair.

Usage

Add the following to your Cargo.toml:

[dependencies]
async-promise = "..."

Basic usage:

#[tokio::main]
async fn main() {
    let (resolve, promise) = async_promise::channel::<i32>();

    // Resolve the promise.
    resolve.into_resolve(42);

    // Read the value.
    // May be read by multiple consumers.
    let value = promise.wait().await;
    assert_eq!(Some(&42), value);
}

Dependencies

~105–455KB
~10K SLoC