rust_utils/
futures.rs

1//! Utilities for dealing with futures and asynchronous Rust APIs
2
3use std::future::Future;
4use tokio::runtime::Runtime;
5use futures::executor::block_on;
6
7/// Convenience function to run a future
8/// until it returns a value
9///
10/// This is useful in synchronous contexts where the .await syntax normally can't
11/// be used
12pub fn exec_future<F: Future>(future: F) -> F::Output {
13    let rt = Runtime::new().unwrap();
14    let guard = rt.enter();
15    let val = block_on(future);
16    drop(guard);
17    val
18}