1use std::task::{Context, Poll};
2
3use futures::Future;
4use pin_project::pin_project;
5
6use tokio::sync::oneshot;
7
8use crate::actor::ActorError;
9
10#[pin_project(project = ActorFutureProjection)]
11pub struct ActorFuture<S, E> {
12 #[pin]
13 pub(crate) inner: oneshot::Receiver<Result<S, E>>,
14}
15
16impl<S, E> Future for ActorFuture<S, E>
17where
18 E: From<ActorError>,
19{
20 type Output = Result<S, E>;
21
22 fn poll(self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
23 match self.project().inner.poll(cx) {
24 Poll::Ready(Ok(res)) => Poll::Ready(res),
25 Poll::Ready(Err(_)) => Poll::Ready(Err(ActorError::ActorHungUp.into())),
26 Poll::Pending => Poll::Pending,
27 }
28 }
29}