Crates.io | poll-promise |
lib.rs | poll-promise |
version | 0.2.1 |
source | src |
created_at | 2022-01-10 12:34:48.330463 |
updated_at | 2023-09-29 19:05:34.4318 |
description | Poll the result of an async operation in a game or immediate mode GUI. |
homepage | https://github.com/EmbarkStudios/poll-promise |
repository | https://github.com/EmbarkStudios/poll-promise |
max_upload_size | |
id | 511353 |
size | 42,788 |
poll-promise
is a Rust crate for polling the result of a concurrent (e.g. async
) operation. This is in particular 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 = poll_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 icon
}
If you enable the tokio
feature you can use poll-promise
with the tokio runtime.
The crate is primarily useful as a high-level building block in apps.
This crate provides convenience methods to spawn threads and tokio tasks, and methods that block on waiting for a result. This is gererally a bad idea to do in a library, as decisions about execution environments and thread blocking should be left to the app. So we do not recommend using this crate for libraries in its current state.
Similar functionality is provided by:
We welcome community contributions to this project.
Please read our Contributor Guide for more information on how to get started. Please also read our Contributor Terms before you make any contributions.
Any contribution intentionally submitted for inclusion in an Embark Studios project, shall comply with the Rust standard licensing model (MIT OR Apache 2.0) and therefore be dual licensed as described below, without any additional terms or conditions:
This contribution is dual licensed under EITHER OF
at your option.
For clarity, "your" refers to Embark or any other licensee/user of the contribution.