1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Utilities for dealing with futures and asynchronous Rust APIs

use std::future::Future;
use tokio::runtime::Runtime;
use futures::executor::block_on;

/// Convenience function to run a future
/// until it returns a value
///
/// This is useful in synchronous contexts where the .await syntax normally can't
/// be used
pub fn exec_future<F: Future>(future: F) -> F::Output {
    let rt = Runtime::new().unwrap();
    let guard = rt.enter();
    let val = block_on(future);
    drop(guard);
    val
}