oasis_core_runtime/
future.rs

1//! Helper functions to use with the asynchronous Tokio runtime.
2use std::future::Future;
3
4/// Create a new asynchronous Tokio runtime.
5#[cfg(any(target_env = "sgx", feature = "debug-mock-sgx"))]
6pub fn new_tokio_runtime() -> tokio::runtime::Runtime {
7    // In SGX use a trimmed-down version of the Tokio runtime.
8    //
9    // Make sure to update THREADS.md if you change any of the thread-related settings.
10    tokio::runtime::Builder::new_multi_thread()
11        .worker_threads(6)
12        .max_blocking_threads(16)
13        .thread_keep_alive(std::time::Duration::MAX)
14        .enable_all()
15        .build()
16        .unwrap()
17}
18
19/// Create a new asynchronous Tokio runtime.
20#[cfg(not(any(target_env = "sgx", feature = "debug-mock-sgx")))]
21pub fn new_tokio_runtime() -> tokio::runtime::Runtime {
22    // In non-SGX we use a fully-fledged Tokio runtime.
23    tokio::runtime::Runtime::new().unwrap()
24}
25
26/// Runs a future to completion on the current Tokio handle's associated Runtime.
27pub fn block_on<F: Future>(future: F) -> F::Output {
28    tokio::runtime::Handle::current().block_on(future)
29}