Crate Poll Promise
Chester Wyke January 30, 2024 Updated: April 15, 2025 #rust
rust (Series)
Conditional Compilation
Install
Crate Serde
References
Cargo
Toolchain (Nightly)
String Formatting
Time
Crate Tokio
Publish Crate
rustfmt
Single file script
Snippets
CI
Pattern Type State
WASM
Create New Crate
Documentation
JSON
Pattern Builder
Testing
Working with collections of bytes
Thoughts about rust
Are we yet
OnceLock
Crate Actix Web
Stack Overflow
Crate Clap
Crate Poll Promise
Crate Insta
Tips
Create new egui project
Crate CSV
Crate egui
Iterators
Crate Tracing Subscriber
Regex
vscode
Enum Conversion
Macros
lettre
Google APIs
Conditional Compilation
Install
Crate Serde
References
Cargo
Toolchain (Nightly)
String Formatting
Time
Crate Tokio
Publish Crate
rustfmt
Single file script
Snippets
CI
Pattern Type State
WASM
Create New Crate
Documentation
JSON
Pattern Builder
Testing
Working with collections of bytes
Thoughts about rust
Are we yet
OnceLock
Crate Actix Web
Stack Overflow
Crate Clap
Crate Poll Promise
Crate Insta
Tips
Create new egui project
Crate CSV
Crate egui
Iterators
Crate Tracing Subscriber
Regex
vscode
Enum Conversion
Macros
lettre
Google APIs
Source: https://github.com/EmbarkStudios/poll-promise
Foreword
Useful for applications that need to poll an async task instead of just awaiting it because you cannot block the current execution unit. As per their readme not recommended for libraries.
See simple example that uses threads and no async runtime.
A more complete egui application can be found here.
The examples below use cargo script so if you’re not familiar please see my short article on that first.
Example of how to use with Tokio
Put it here instead of in their examples folder because it would have prevented cargo test
from passing because it needs non-default features.
#!/usr/bin/env -S cargo +nightly -Zscript
---cargo
package.edition = "2021"
poll-promise =
tokio = "1.35.1"
---
async
async
Notes from reading documentation
NB: The following have not been tested yet but this is what I thought of when I read the docs
- Promise::new - Useful if you direct access to the Sender
- Promise::from_ready - Useful if no work is needed to resolve the promise but a promise needs to be returned.