loadstar/utilities/
async_block.rs

1use std::future::Future;
2
3
4pub fn run_async<T>(async_operation: impl Future<Output = T>) -> T {
5    // Use `block_in_place` to ensure runtime is dropped in a blocking context
6    tokio::task::block_in_place(|| {
7        // Get the current Tokio runtime handle
8        let handle = tokio::runtime::Handle::current();
9        // Run the async operation using the handle and wait for it to complete
10        handle.block_on(async_operation)
11    })
12}