use crate::definitions::*;
use pi_result::RawResult as Result;
use crate::task::TaskRef;
pub use crate::task::{PanicRecord, TaskError};
use std::future::Future;
use std::marker::PhantomData;
use std::pin::Pin;
use std::rc::Rc;
use std::task::{Context, Poll};
mod output_sealed {
pub trait Sealed {}
}
pub trait OutputMode: output_sealed::Sealed + 'static {}
pub struct SendOutput;
impl output_sealed::Sealed for SendOutput {}
impl OutputMode for SendOutput {}
pub struct LocalOutput(PhantomData<Rc<()>>);
impl output_sealed::Sealed for LocalOutput {}
impl OutputMode for LocalOutput {}
#[must_use = "保留以领取结果,或释放以明确放弃;释放不会自动取消任务"]
pub struct JoinHandle<T, M: Send + Sync + 'static = (), K: OutputMode = SendOutput> {
pub(crate) task: TaskRef,
pub(crate) consumed: bool,
pub(crate) marker: PhantomData<(T, M, K)>,
}
impl<T, M: Send + Sync + 'static, K: OutputMode> Unpin for JoinHandle<T, M, K> {}
impl<T, M: Send + Sync + 'static, K: OutputMode> JoinHandle<T, M, K> {
pub fn id(&self) -> TaskId {
join_id_inner(self)
}
}
impl<T, M: Send + Sync + 'static, K: OutputMode> JoinHandle<T, M, K> {
pub fn snapshot(&self) -> TaskSnapshot {
join_snapshot_inner(self)
}
}
impl<T, M: Send + Sync + 'static, K: OutputMode> JoinHandle<T, M, K> {
pub fn metadata(&self) -> &M {
join_metadata_inner(self)
}
}
impl<T, M: Send + Sync + 'static, K: OutputMode> Future for JoinHandle<T, M, K> {
type Output = Result<T, TaskError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
join_poll_inner(self, cx)
}
}
impl<T, M: Send + Sync + 'static, K: OutputMode> Drop for JoinHandle<T, M, K> {
fn drop(&mut self) {
join_drop_inner(self)
}
}
include!("join_inner.rs");