pub type ResponseActFuture<A, I> = LocalBoxActorFuture<A, I>;
Expand description
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
, 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)
}),
)
}
}
Aliased Type§
struct ResponseActFuture<A, I> {}