Skip to main content

zeromq/async_rt/task/
join_handle.rs

1#[cfg(feature = "async-dispatcher-runtime")]
2use async_dispatcher as rt_task;
3#[cfg(feature = "async-std-runtime")]
4use async_std::task as rt_task;
5#[cfg(feature = "tokio-runtime")]
6use tokio::task as rt_task;
7
8use super::JoinError;
9
10use std::future::Future;
11use std::pin::Pin;
12use std::task::{Context, Poll};
13
14pub struct JoinHandle<T>(rt_task::JoinHandle<T>);
15impl<T> Future for JoinHandle<T> {
16    type Output = Result<T, JoinError>;
17
18    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
19        // In async-std, the program aborts on panic so results arent returned. To
20        // unify with tokio, we simply make an `Ok` result.
21        let result = rt_task::JoinHandle::poll(Pin::new(&mut self.0), cx);
22        #[cfg(any(feature = "async-std-runtime", feature = "async-dispatcher-runtime"))]
23        return result.map(Ok);
24        #[cfg(feature = "tokio-runtime")]
25        return result.map_err(|e| e.into());
26    }
27}
28impl<T> From<rt_task::JoinHandle<T>> for JoinHandle<T> {
29    fn from(h: rt_task::JoinHandle<T>) -> Self {
30        Self(h)
31    }
32}