1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use once_cell::sync::OnceCell;
use tokio::runtime::Runtime;
pub use tokio::sync::{
mpsc::{channel, Receiver, Sender},
Mutex, RwLock,
};
use std::future::Future;
static RUNTIME: OnceCell<Runtime> = OnceCell::new();
pub fn block_on<F: Future>(task: F) -> F::Output {
let runtime = RUNTIME.get_or_init(|| Runtime::new().unwrap());
runtime.block_on(task)
}
pub fn spawn<F>(task: F)
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
let runtime = RUNTIME.get_or_init(|| Runtime::new().unwrap());
runtime.spawn(task);
}