[−][src]Trait actix::fut::ActorFuture
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
type Output
[src]
The type of value that this future will resolved with if it is successful.
type Actor: Actor
[src]
The actor within which this future runs
Required methods
pub fn poll(
self: Pin<&mut Self>,
srv: &mut Self::Actor,
ctx: &mut <Self::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
srv: &mut Self::Actor,
ctx: &mut <Self::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
Provided methods
pub fn map<F, U>(self, f: F) -> Map<Self, F> where
F: FnOnce(Self::Output, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> U,
Self: Sized,
[src]
F: FnOnce(Self::Output, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> U,
Self: Sized,
Map this future's result to a different type, returning a new future of the resulting type.
pub fn then<F, B>(self, f: F) -> Then<Self, B, F> where
F: FnOnce(Self::Output, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> B,
B: IntoActorFuture<Actor = Self::Actor>,
Self: Sized,
[src]
F: FnOnce(Self::Output, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> B,
B: IntoActorFuture<Actor = Self::Actor>,
Self: Sized,
Chain on a computation for when a future finished, passing the result of
the future to the provided closure f
.
pub fn timeout(self, timeout: Duration) -> Timeout<Self> where
Self: Sized,
[src]
Self: Sized,
Add timeout to futures chain.
err
value get returned as a timeout error.
Implementations on Foreign Types
impl<F: ActorFuture + Unpin + ?Sized> ActorFuture for Box<F>
[src]
type Output = F::Output
type Actor = F::Actor
pub fn poll(
self: Pin<&mut Self>,
srv: &mut Self::Actor,
ctx: &mut <Self::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
srv: &mut Self::Actor,
ctx: &mut <Self::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
impl<P> ActorFuture for Pin<P> where
P: Unpin + DerefMut,
<P as Deref>::Target: ActorFuture,
[src]
P: Unpin + DerefMut,
<P as Deref>::Target: ActorFuture,
type Output = <<P as Deref>::Target as ActorFuture>::Output
type Actor = <<P as Deref>::Target as ActorFuture>::Actor
pub fn poll(
self: Pin<&mut Self>,
srv: &mut Self::Actor,
ctx: &mut <Self::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
srv: &mut Self::Actor,
ctx: &mut <Self::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
Implementors
impl ActorFuture for TcpConnector
[src]
type Output = Result<TcpStream, ResolverError>
type Actor = Resolver
pub fn poll(
self: Pin<&mut Self>,
_: &mut Resolver,
_: &mut Context<Resolver>,
cx: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
_: &mut Resolver,
_: &mut Context<Resolver>,
cx: &mut Context<'_>
) -> Poll<Self::Output>
impl<A> ActorFuture for TimerFunc<A> where
A: Actor,
[src]
A: Actor,
type Output = ()
type Actor = A
pub fn poll(
self: Pin<&mut Self>,
act: &mut Self::Actor,
ctx: &mut <Self::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
act: &mut Self::Actor,
ctx: &mut <Self::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
impl<A, B> ActorFuture for Either<A, B> where
A: ActorFuture,
B: ActorFuture<Output = A::Output, Actor = A::Actor>,
[src]
A: ActorFuture,
B: ActorFuture<Output = A::Output, Actor = A::Actor>,
type Output = A::Output
type Actor = A::Actor
pub fn poll(
self: Pin<&mut Self>,
act: &mut A::Actor,
ctx: &mut <A::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<A::Output>
[src]
self: Pin<&mut Self>,
act: &mut A::Actor,
ctx: &mut <A::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<A::Output>
impl<A, B, F> ActorFuture for Then<A, B, F> where
A: ActorFuture,
B: IntoActorFuture<Actor = A::Actor>,
F: FnOnce(A::Output, &mut A::Actor, &mut <A::Actor as Actor>::Context) -> B,
[src]
A: ActorFuture,
B: IntoActorFuture<Actor = A::Actor>,
F: FnOnce(A::Output, &mut A::Actor, &mut <A::Actor as Actor>::Context) -> B,
type Output = B::Output
type Actor = A::Actor
pub fn poll(
self: Pin<&mut Self>,
act: &mut A::Actor,
ctx: &mut <A::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<B::Output>
[src]
self: Pin<&mut Self>,
act: &mut A::Actor,
ctx: &mut <A::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<B::Output>
impl<F> ActorFuture for Timeout<F> where
F: ActorFuture,
[src]
F: ActorFuture,
type Output = Result<F::Output, ()>
type Actor = F::Actor
pub fn poll(
self: Pin<&mut Self>,
act: &mut F::Actor,
ctx: &mut <F::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
act: &mut F::Actor,
ctx: &mut <F::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
impl<F, A> ActorFuture for FutureWrap<F, A> where
F: Future,
A: Actor,
[src]
F: Future,
A: Actor,
type Output = F::Output
type Actor = A
pub fn poll(
self: Pin<&mut Self>,
_: &mut Self::Actor,
_: &mut <Self::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
_: &mut Self::Actor,
_: &mut <Self::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<Self::Output>
impl<S, F, Fut, T> ActorFuture for StreamFold<S, F, Fut, T> where
S: ActorStream,
F: FnMut(T, S::Item, &mut S::Actor, &mut <S::Actor as Actor>::Context) -> Fut,
Fut: IntoActorFuture<Output = T, Actor = S::Actor>,
Fut::Future: ActorFuture,
[src]
S: ActorStream,
F: FnMut(T, S::Item, &mut S::Actor, &mut <S::Actor as Actor>::Context) -> Fut,
Fut: IntoActorFuture<Output = T, Actor = S::Actor>,
Fut::Future: ActorFuture,
type Output = T
type Actor = S::Actor
pub fn poll(
self: Pin<&mut Self>,
act: &mut S::Actor,
ctx: &mut <S::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<T>
[src]
self: Pin<&mut Self>,
act: &mut S::Actor,
ctx: &mut <S::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<T>
impl<S: ActorStream> ActorFuture for StreamFinish<S>
[src]
type Output = ()
type Actor = S::Actor
pub fn poll(
self: Pin<&mut Self>,
act: &mut S::Actor,
ctx: &mut <S::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<()>
[src]
self: Pin<&mut Self>,
act: &mut S::Actor,
ctx: &mut <S::Actor as Actor>::Context,
task: &mut Context<'_>
) -> Poll<()>
impl<T, A> ActorFuture for Ready<T, A> where
A: Actor,
[src]
A: Actor,
type Output = T
type Actor = A
pub fn poll(
self: Pin<&mut Self>,
_: &mut Self::Actor,
_: &mut <Self::Actor as Actor>::Context,
_: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
_: &mut Self::Actor,
_: &mut <Self::Actor as Actor>::Context,
_: &mut Context<'_>
) -> Poll<Self::Output>
impl<T, E, A> ActorFuture for FutureResult<T, E, A> where
A: Actor,
[src]
A: Actor,
type Output = Result<T, E>
type Actor = A
pub fn poll(
self: Pin<&mut Self>,
_: &mut Self::Actor,
_: &mut <Self::Actor as Actor>::Context,
_: &mut Context<'_>
) -> Poll<Self::Output>
[src]
self: Pin<&mut Self>,
_: &mut Self::Actor,
_: &mut <Self::Actor as Actor>::Context,
_: &mut Context<'_>
) -> Poll<Self::Output>
impl<U, A, F> ActorFuture for Map<A, F> where
A: ActorFuture,
F: FnOnce(A::Output, &mut A::Actor, &mut <A::Actor as Actor>::Context) -> U,
[src]
A: ActorFuture,
F: FnOnce(A::Output, &mut A::Actor, &mut <A::Actor as Actor>::Context) -> U,