13 lines
446 B
Rust
13 lines
446 B
Rust
|
use std::future::Future;
|
||
|
|
||
|
|
||
|
pub fn run_async<T>(async_operation: impl Future<Output = T>) -> T {
|
||
|
// Use `block_in_place` to ensure runtime is dropped in a blocking context
|
||
|
tokio::task::block_in_place(|| {
|
||
|
// Get the current Tokio runtime handle
|
||
|
let handle = tokio::runtime::Handle::current();
|
||
|
// Run the async operation using the handle and wait for it to complete
|
||
|
handle.block_on(async_operation)
|
||
|
})
|
||
|
}
|