use std::{
future::Future,
ops::DerefMut,
pin::Pin,
task::{Context, Poll},
};
use crate::error::Result;
#[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 = Result<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) => {
use crate::error::ErrorKind;
Pin::new(handle).poll(cx).map(|result| {
result.map_err(|e| {
ErrorKind::InternalError {
message: format!("{}", e),
}
.into()
})
})
}
#[cfg(feature = "async-std-runtime")]
Self::AsyncStd(ref mut handle) => Pin::new(handle).poll(cx).map(Ok),
}
}
}