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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use super::{SpawnJoinHandle, Spawning};
#[cfg(not(feature = "log"))]
use crate::log;
use async_std::task::{spawn_blocking, Builder, JoinHandle};
use core::future::Future as CoreFuture;
pub struct Runtime;
impl<T: Send + Sync + Unpin> SpawnJoinHandle<T> for JoinHandle<T> {}
impl<T> Spawning<T, JoinHandle<T>, T> for Runtime {
fn spawn<F>(fut: F) -> JoinHandle<T>
where
F: CoreFuture<Output = T> + Send + 'static,
T: Send + 'static,
{
log::debug!("Spawn New future");
Builder::new().spawn(fut).expect("Spawn task failed")
}
fn spawn_blocking<F>(fut: F) -> JoinHandle<T>
where
F: FnOnce() -> T + Send + 'static,
T: Send + 'static,
{
log::debug!("Spawn blocking future");
spawn_blocking(fut)
}
fn block_on<F>(fut: F) -> T
where
F: CoreFuture<Output = T>,
{
log::debug!("Blocking executing future");
Builder::new().blocking(fut)
}
fn spawn_local<F>(fut: F) -> JoinHandle<T>
where
F: CoreFuture<Output = T> + 'static,
F::Output: 'static,
{
log::debug!("Spawn local future");
Builder::new().local(fut).expect("Spawn task failed")
}
}