[go: up one dir, main page]

poll-promise 0.1.0

Poll the result of an async operation in a game or immediate mode GUI.
Documentation

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:

# fn something_slow() {}
# use poll_promise::Promise;
#
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
}

If you enable the tokio feature you can use poll-promise with the tokio runtime to run async tasks using [Promise::spawn_async] and [Promise::spawn_blocking].