async-promise

Crates.ioasync-promise
lib.rsasync-promise
version0.1.0
created_at2025-04-29 20:30:07.670162+00
updated_at2025-04-29 20:30:07.670162+00
descriptionAsync promise which resolves once and may be read by multiple consumers.
homepage
repositoryhttps://github.com/hydro-project/async-ssh2-russh
max_upload_size
id1654031
size20,060
Mingwei Samuel (MingweiSamuel)

documentation

https://docs.rs/async-promise/

README

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);
}
Commit count: 3

cargo fmt