use std::fmt::Debug;
use std::pin::Pin;
use std::task::{Context, Poll};
use futures_channel::oneshot;
pub struct JoinHandle<T>(pub(crate) JoinHandleInner<T>);
pub(crate) enum JoinHandleInner<T> {
#[cfg(feature = "tokio")]
Tokio(::tokio::task::JoinHandle<T>),
Custom(oneshot::Receiver<T>),
}
impl<T> Future for JoinHandle<T> {
type Output = T;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match &mut self.get_mut().0 {
#[cfg(feature = "tokio")]
JoinHandleInner::Tokio(jh) => Pin::new(jh).poll(cx).map(|res| res.expect("spawned task panicked")),
JoinHandleInner::Custom(rx) => Pin::new(rx).poll(cx).map(|res| res.expect("spawned task panicked")),
}
}
}
impl<T> Debug for JoinHandle<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("JoinHandle").finish_non_exhaustive()
}
}