[][src]Type Definition actix::ResponseActFuture

type ResponseActFuture<A, I> = Pin<Box<dyn ActorFuture<Output = I, Actor = A>>>;

A specialized actor future for asynchronous message handling.

Intended be used when the future returned will, at some point, need to access Actor's internal state or context in order to finish. Check ActorFuture for available methods for accessing Actor's internal state.

Note

It's important to keep in mind that the provided AsyncContext, Context, does not enforce the poll of any ActorFuture to be exclusive. Therefore, if other instances of ActorFuture are spawned into this Context their execution won't necessarily be atomic. Check AtomicResponse if you need exclusive access over the actor.

Examples

use actix::prelude::*;

#[derive(Message)]
#[rtype(result = "Result<usize, ()>")]
struct Msg;

struct MyActor;

impl Actor for MyActor {
    type Context = Context<Self>;
}

impl Handler<Msg> for MyActor {
    type Result = ResponseActFuture<Self, Result<usize, ()>>;

    fn handle(&mut self, _: Msg, _: &mut Context<Self>) -> Self::Result {
        Box::pin(
            async {
                // Some async computation
                42
            }
            .into_actor(self) // converts future to ActorFuture
            .map(|res, _act, _ctx| {
                // Do some computation with actor's state or context
                Ok(res)
            }),
        )
    }
}

Trait Implementations

impl<A, M, T: 'static> MessageResponse<A, M> for ResponseActFuture<A, T> where
    A: Actor,
    M: Message<Result = T>,
    A::Context: AsyncContext<A>, 
[src]