1use std::pin::Pin;
4use std::task::{Context, Poll};
5
6use crate::error;
7
8type TaskFuture<T> = Pin<Box<dyn Future<Output = Result<T, error::Error>> + Send + Sync>>;
10
11pub struct TaskHandle<T> {
17 future: TaskFuture<T>,
18}
19
20impl<T> TaskHandle<T> {
21 pub(crate) fn from_future(
27 future: impl Future<Output = Result<T, error::Error>> + Send + Sync + 'static,
28 ) -> Self {
29 Self {
30 future: Box::pin(future),
31 }
32 }
33}
34
35impl<T> Future for TaskHandle<T> {
36 type Output = Result<T, error::Error>;
37
38 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
39 self.future.as_mut().poll(cx)
40 }
41}