A collection of asynchronous/future utilities for Rust.
- Blocking Execution of Asynchronous Futures: This crate provides a utility function,
block_on
, that allows you to execute asynchronous code synchronously when necessary. This is only available with theblock_on
feature flag enabled.
To use this crate in your Rust project, add it as a dependency in your Cargo.toml
:
[dependencies]
future_utils = "0.1.0"
The block_on function is used to block the current thread and wait for the provided asynchronous future to complete its execution, returning the result once it's finished.
use future_utils::block_on;
async fn my_async_function() -> i32 {
// Some asynchronous computation
42
}
fn main() {
let result = block_on(my_async_function());
println!("Result: {}", result);
}
Warning: Blocking on asynchronous code should be used with caution, as it can lead to performance issues and should generally be avoided when possible. Consider alternative approaches like using async functions and awaiting the results in an asynchronous context whenever feasible.
As this crate is still in very early development, proper contribution guidelines have not been established.
This crate is dual-licensed under the MIT License and the Apache License 2.0. You may choose either of them when using this crate.
- The MIT License: LICENSE-MIT or here
- The Apache License 2.0: LICENSE-APACHE or here