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
use std::{
future::Future,
ops::DerefMut,
pin::Pin,
task::{Context, Poll},
};
#[derive(Debug)]
pub(crate) enum AsyncJoinHandle<T> {
#[cfg(feature = "tokio-runtime")]
Tokio(tokio::task::JoinHandle<T>),
#[cfg(feature = "async-std-runtime")]
AsyncStd(async_std::task::JoinHandle<T>),
}
impl<T> Future for AsyncJoinHandle<T> {
type Output = T;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.deref_mut() {
#[cfg(feature = "tokio-runtime")]
Self::Tokio(ref mut handle) => Pin::new(handle).poll(cx).map(|result| result.unwrap()),
#[cfg(feature = "async-std-runtime")]
Self::AsyncStd(ref mut handle) => Pin::new(handle).poll(cx),
}
}
}