elph_agent/runtime/mod.rs
1use std::future::Future;
2use std::io;
3
4/// Runs an async future on a current-thread Tokio runtime.
5pub fn block_on<F, T>(future: F) -> T
6where
7 F: Future<Output = T>,
8{
9 tokio::runtime::Builder::new_current_thread()
10 .enable_all()
11 .build()
12 .expect("failed to create tokio runtime")
13 .block_on(future)
14}
15
16/// Runs an async future, returning runtime construction errors as [`io::Error`].
17pub fn try_block_on<F, T>(future: F) -> io::Result<T>
18where
19 F: Future<Output = T>,
20{
21 Ok(tokio::runtime::Builder::new_current_thread()
22 .enable_all()
23 .build()?
24 .block_on(future))
25}