Trait actix::fut::future::ActorFuture [−][src]
Trait for types which are a placeholder of a value that may become available at some later point in time.
ActorFuture
is very similar to a regular Future
, only with subsequent combinator closures accepting the actor and its context, in addition to the result.
ActorFuture
allows for use cases where future processing requires access to the actor or its context.
Here is an example of a handler on a single actor, deferring work to another actor, and then updating the initiating actor’s state:
use actix::prelude::*; // The response type returned by the actor future type OriginalActorResponse = (); // The error type returned by the actor future type MessageError = (); // This is the needed result for the DeferredWork message // It's a result that combine both Response and Error from the future response. type DeferredWorkResult = Result<OriginalActorResponse, MessageError>; impl Handler<DeferredWork> for OriginalActor { // Notice the `Response` is an `ActorFuture`-ized version of `Self::Message::Result`. type Result = ResponseActFuture<Self, Result<OriginalActorResponse, MessageError>>; fn handle(&mut self, _msg: DeferredWork, _ctx: &mut Context<Self>) -> Self::Result { // this creates a `Future` representing the `.send` and subsequent `Result` from // `other_actor` let send_to_other = self.other_actor .send(OtherMessage {}); // Wrap that `Future` so subsequent chained handlers can access // the `actor` (`self` in the synchronous code) as well as the context. let send_to_other = actix::fut::wrap_future::<_, Self>(send_to_other); // once the wrapped future resolves, update this actor's state let update_self = send_to_other.map(|result, actor, _ctx| { // Actor's state updated here match result { Ok(v) => { actor.inner_state.update_from(v); Ok(()) }, // Failed to send message to other_actor Err(_e) => Err(()), } }); // return the wrapped future Box::pin(update_self) } }
See also into_actor, which provides future conversion using trait
Associated Types
Loading content...Required methods
fn poll(
self: Pin<&mut Self>,
srv: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
srv: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
Implementations on Foreign Types
impl<A, B, Act> ActorFuture<Act> for Either<A, B> where
A: ActorFuture<Act>,
B: ActorFuture<Act, Output = A::Output>,
Act: Actor,
[src]
A: ActorFuture<Act>,
B: ActorFuture<Act, Output = A::Output>,
Act: Actor,
type Output = A::Output
fn poll(
self: Pin<&mut Self>,
act: &mut Act,
ctx: &mut Act::Context,
task: &mut Context<'_>
) -> Poll<A::Output>
[src]
self: Pin<&mut Self>,
act: &mut Act,
ctx: &mut Act::Context,
task: &mut Context<'_>
) -> Poll<A::Output>
impl<F: ?Sized, A> ActorFuture<A> for Box<F> where
F: ActorFuture<A> + Unpin,
A: Actor,
[src]
F: ActorFuture<A> + Unpin,
A: Actor,
type Output = F::Output
fn poll(
self: Pin<&mut Self>,
srv: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
srv: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
impl<P, A> ActorFuture<A> for Pin<P> where
P: Unpin + DerefMut,
<P as Deref>::Target: ActorFuture<A>,
A: Actor,
[src]
P: Unpin + DerefMut,
<P as Deref>::Target: ActorFuture<A>,
A: Actor,
type Output = <<P as Deref>::Target as ActorFuture<A>>::Output
fn poll(
self: Pin<&mut Self>,
srv: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
srv: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
Implementors
impl<A> ActorFuture<A> for TimerFunc<A> where
A: Actor,
[src]
A: Actor,
type Output = ()
fn poll(
self: Pin<&mut Self>,
act: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
act: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
impl<A, B, F, Act> ActorFuture<Act> for Then<A, B, F> where
A: ActorFuture<Act>,
B: ActorFuture<Act>,
F: FnOnce(A::Output, &mut Act, &mut Act::Context) -> B,
Act: Actor,
[src]
A: ActorFuture<Act>,
B: ActorFuture<Act>,
F: FnOnce(A::Output, &mut Act, &mut Act::Context) -> B,
Act: Actor,
type Output = B::Output
fn poll(
self: Pin<&mut Self>,
act: &mut Act,
ctx: &mut Act::Context,
task: &mut Context<'_>
) -> Poll<B::Output>
[src]
self: Pin<&mut Self>,
act: &mut Act,
ctx: &mut Act::Context,
task: &mut Context<'_>
) -> Poll<B::Output>
impl<F, A> ActorFuture<A> for FutureWrap<F, A> where
F: Future,
A: Actor,
[src]
F: Future,
A: Actor,
type Output = F::Output
fn poll(
self: Pin<&mut Self>,
_: &mut A,
_: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
_: &mut A,
_: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
impl<F, A> ActorFuture<A> for Timeout<F> where
F: ActorFuture<A>,
A: Actor,
[src]
F: ActorFuture<A>,
A: Actor,
type Output = Result<F::Output, ()>
fn poll(
self: Pin<&mut Self>,
act: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
act: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
impl<S, A> ActorFuture<A> for Finish<S> where
S: ActorStream<A>,
A: Actor,
[src]
S: ActorStream<A>,
A: Actor,
type Output = ()
fn poll(
self: Pin<&mut Self>,
act: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<()>
[src]
self: Pin<&mut Self>,
act: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<()>
impl<S, A, C> ActorFuture<A> for Collect<S, C> where
S: ActorStream<A>,
A: Actor,
C: Default + Extend<S::Item>,
[src]
S: ActorStream<A>,
A: Actor,
C: Default + Extend<S::Item>,
type Output = C
fn poll(
self: Pin<&mut Self>,
act: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
act: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
impl<S, A, F, Fut> ActorFuture<A> for Fold<S, F, Fut, Fut::Output> where
S: ActorStream<A>,
A: Actor,
F: FnMut(Fut::Output, S::Item, &mut A, &mut A::Context) -> Fut,
Fut: ActorFuture<A>,
[src]
S: ActorStream<A>,
A: Actor,
F: FnMut(Fut::Output, S::Item, &mut A, &mut A::Context) -> Fut,
Fut: ActorFuture<A>,
type Output = Fut::Output
fn poll(
self: Pin<&mut Self>,
act: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
act: &mut A,
ctx: &mut A::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
impl<T, A> ActorFuture<A> for Ready<T> where
A: Actor,
[src]
A: Actor,
type Output = T
fn poll(
self: Pin<&mut Self>,
_: &mut A,
_: &mut A::Context,
cx: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
_: &mut A,
_: &mut A::Context,
cx: &mut Context<'_>
) -> Poll<Self::Output>
impl<U, Fut, A, F> ActorFuture<A> for Map<Fut, F> where
Fut: ActorFuture<A>,
A: Actor,
F: FnOnce(Fut::Output, &mut A, &mut A::Context) -> U,
[src]
Fut: ActorFuture<A>,
A: Actor,
F: FnOnce(Fut::Output, &mut A, &mut A::Context) -> U,