Crate poll_promise
source ·Expand description
poll-promise is a Rust crate for polling the result of a concurrent (e.g. async) operation.
It is particularly useful in games and immediate mode GUI:s, where one often wants to start a background operation and then ask “are we there yet?” on each subsequent frame until the operation completes.
Example:
let promise = Promise::spawn_thread("slow_operation", something_slow);
// Then in the game loop or immediate mode GUI code:
if let Some(result) = promise.ready() {
// Use/show result
} else {
// Show a loading screen
}Features
poll-promise can be used with any async runtime, but a few convenience methods are added
when compiled with the following features:
tokio
If you enable the tokio feature you can use Promise::spawn_async and Promise::spawn_blocking
which will spawn tasks in the surrounding tokio runtime.
web
If you enable the web feature you can use Promise::spawn_async which will spawn tasks using
wasm_bindgen_futures::spawn_local.
Structs
- A promise that waits for the reception of a single value, presumably from some async task.
- Used to send a result to a
Promise.