| Crates.io | sync-run-async |
| lib.rs | sync-run-async |
| version | 0.1.2 |
| created_at | 2025-04-01 00:37:04.723579+00 |
| updated_at | 2025-07-12 22:50:34.060185+00 |
| description | This crate provides a way to synchronously run async code. |
| homepage | |
| repository | https://github.com/klebs6/klebs-general |
| max_upload_size | |
| id | 1614257 |
| size | 144,430 |
This crate provides a way to synchronously run async code.
sync-run-async is a highly efficient utility for executing asynchronous futures from synchronous contexts in Rust applications. It leverages existing Tokio runtime handles when available and creates new ones when necessary, eliminating runtime nesting concerns. This crate is particularly beneficial for developers who need a reliable way to bridge synchronous and asynchronous code without introducing runtime complexity.
To use sync-run-async, simply call the sync_run_async function with your future:
use workspacer_3p::sync_run_async;
async fn my_async_function() -> i32 {
42
}
fn main() {
let result = sync_run_async(my_async_function());
println!("Result: {}", result);
}
Ideal for scenarios where asynchronous operations must be launched from synchronous code but need to safely handle runtime context determination. Perfect for scenarios like testing or embedding asynchronous operation in traditionally synchronous codebases.
Add the following to your Cargo.toml:
[dependencies]
sync-run-async = "0.5.0"
This crate is open-source and contributors are welcomed. The code repository is hosted on GitHub. Please adhere to the contributor guidelines.
Licensed under the MIT License. See the LICENSE file for details.