use std::{
future::Future,
pin::Pin,
task::{
Context,
Poll,
},
};
use oneshot::AsyncReceiver;
use super::{
TaskExecutionError,
TaskResult,
};
pub struct TaskHandleFuture<R, E> {
receiver: AsyncReceiver<TaskResult<R, E>>,
}
impl<R, E> TaskHandleFuture<R, E> {
#[inline]
pub(crate) const fn new(receiver: AsyncReceiver<TaskResult<R, E>>) -> Self {
Self { receiver }
}
}
impl<R, E> Future for TaskHandleFuture<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.receiver)
.poll(cx)
.map(|result| result.unwrap_or(Err(TaskExecutionError::Dropped)))
}
}