use std::time::Duration;
use tokio::task::LocalSet;
pub(crate) async fn sleep(duration: Duration) {
tokio::time::sleep(duration).await
}
pub(crate) fn block_on_current_thread<F, O>(f: F) -> O
where
F: Future<Output = O>,
{
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Cannot build local tokio runtime");
LocalSet::new().block_on(&runtime, f)
}
#[cfg(feature = "remote")]
pub(crate) fn new(worker_threads: usize, blocking_threads: usize) -> std::io::Result<tokio::runtime::Runtime> {
assert!(worker_threads > 0, "Parameter worker_threads must be larger than 0");
assert!(blocking_threads > 0, "Parameter blocking_threads must be larger than 0");
tokio::runtime::Builder::new_multi_thread()
.worker_threads(worker_threads)
.max_blocking_threads(blocking_threads) .enable_all()
.build()
}