1use std::{
2 future::Future,
3 pin::Pin,
4 task::{Context, Poll},
5};
6
7use crate::{Actor, ActorRef, Mailbox};
8
9pub struct ActorRun<A: Actor> {
13 future: Pin<Box<dyn Future<Output = Result<A, A::Error>> + Send>>,
14}
15
16impl<A: Actor + Send + 'static> ActorRun<A> {
17 pub fn new(mut actor: A, mailbox_size: Option<usize>) -> (ActorRef<A>, Self) {
19 let (mailbox, actor_ref) = Mailbox::new(mailbox_size);
20
21 let future = Box::pin(async move {
22 actor.run_with(mailbox).await?;
23 Ok(actor)
24 });
25
26 (actor_ref, ActorRun { future })
27 }
28}
29
30impl<A: Actor + Send + 'static> Future for ActorRun<A> {
31 type Output = Result<A, A::Error>;
32
33 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
34 self.future.as_mut().poll(cx)
35 }
36}