use std::{
future::Future,
pin::Pin,
sync::Arc,
task::{
Context,
Poll,
},
};
use qubit_executor::{
TaskHandle,
TaskResult,
};
use crate::{
pending_cancel::PendingCancel,
rayon_executor_service_state::RayonExecutorServiceState,
};
pub struct RayonTaskHandle<R, E> {
inner: TaskHandle<R, E>,
task_id: usize,
state: Arc<RayonExecutorServiceState>,
cancel: PendingCancel,
}
impl<R, E> RayonTaskHandle<R, E> {
pub(crate) fn new(
inner: TaskHandle<R, E>,
task_id: usize,
state: Arc<RayonExecutorServiceState>,
cancel: PendingCancel,
) -> Self {
Self {
inner,
task_id,
state,
cancel,
}
}
#[inline]
pub fn get(self) -> TaskResult<R, E> {
self.inner.get()
}
#[inline]
pub fn cancel(&self) -> bool {
self.state.cancel_pending_task(self.task_id, &self.cancel)
}
#[inline]
pub fn is_done(&self) -> bool {
self.inner.is_done()
}
}
impl<R, E> Future for RayonTaskHandle<R, E> {
type Output = TaskResult<R, E>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut();
Pin::new(&mut this.inner).poll(cx)
}
}