use std::marker::PhantomData;
use std::pin::Pin;
use std::task;
use events_once::RawLocalPooledReceiver;
#[derive(Debug)]
pub struct JoinHandle<R: 'static> {
rx: RawLocalPooledReceiver<R>,
_single_threaded: PhantomData<*const ()>,
}
impl<R: 'static> JoinHandle<R> {
pub(crate) fn new(rx: RawLocalPooledReceiver<R>) -> Self {
Self {
rx,
_single_threaded: PhantomData,
}
}
}
impl<R: 'static> Future for JoinHandle<R> {
type Output = R;
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll<Self::Output> {
unsafe { self.map_unchecked_mut(|x| &mut x.rx) }
.poll(cx)
.map(|x| x.expect("join handle is no longer connected - the task failed to reach completion"))
}
}
#[cfg(test)]
mod tests {
use static_assertions::{assert_impl_all, assert_not_impl_any};
use super::*;
assert_not_impl_any!(JoinHandle<u8>: Send, Sync);
assert_impl_all!(JoinHandle<u8>: Unpin);
}