pub trait ActorFuture {
type Item;
type Error;
type Actor: Actor;
fn poll(
&mut self,
srv: &mut Self::Actor,
ctx: &mut <Self::Actor as Actor>::Context
) -> Result<Async<Self::Item>, Self::Error>;
fn map<F, U>(self, f: F) -> Map<Self, F>
where
F: FnOnce(Self::Item, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> U,
Self: Sized,
{ ... }
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
where
F: FnOnce(Self::Error, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> E,
Self: Sized,
{ ... }
fn drop_err(self) -> DropErr<Self>
where
Self: Sized,
{ ... }
fn from_err<E>(self) -> FromErr<Self, E>
where
E: From<Self::Error>,
Self: Sized,
{ ... }
fn then<F, B>(self, f: F) -> Then<Self, B, F>
where
F: FnOnce(Result<Self::Item, Self::Error>, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> B,
B: IntoActorFuture<Actor = Self::Actor>,
Self: Sized,
{ ... }
fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
where
F: FnOnce(Self::Item, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> B,
B: IntoActorFuture<Error = Self::Error, Actor = Self::Actor>,
Self: Sized,
{ ... }
fn timeout(self, timeout: Duration, err: Self::Error) -> Timeout<Self>
where
Self: Sized,
{ ... }
}
Expand description
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:
impl Message for SomeMessage {
type Result = ();
}
impl Handler<DeferredWork> for OriginalActor {
type Result = ResponseActFuture<Self, (), Error>;
fn handle(&mut self, _msg: Refresh, ctx: &mut Context<Self>) -> Self::Result {
let send_to_other = self.other_actor_addr
.send(OtherMessage::new())
.map_err(Error::from);
let update_self =
wrap_future::<_, Self>(send_to_other).map(|result, actor, _ctx| {
// Actor's state updated here
actor.inner_state.update_from(result);
});
// return the wrapping future
Box::new(update_self);
}
}
See also into_actor, which provides future conversion using trait
Required Associated Types
Required Methods
fn poll(
&mut self,
srv: &mut Self::Actor,
ctx: &mut <Self::Actor as Actor>::Context
) -> Result<Async<Self::Item>, Self::Error>
Provided Methods
sourcefn map<F, U>(self, f: F) -> Map<Self, F>where
F: FnOnce(Self::Item, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> U,
Self: Sized,
fn map<F, U>(self, f: F) -> Map<Self, F>where
F: FnOnce(Self::Item, &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.
sourcefn map_err<F, E>(self, f: F) -> MapErr<Self, F>where
F: FnOnce(Self::Error, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> E,
Self: Sized,
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>where
F: FnOnce(Self::Error, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> E,
Self: Sized,
Map this future’s error to a different error, returning a new future.
sourcefn drop_err(self) -> DropErr<Self>where
Self: Sized,
fn drop_err(self) -> DropErr<Self>where
Self: Sized,
Drop this future’s error, returning a new future.
sourcefn from_err<E>(self) -> FromErr<Self, E>where
E: From<Self::Error>,
Self: Sized,
fn from_err<E>(self) -> FromErr<Self, E>where
E: From<Self::Error>,
Self: Sized,
Map this future’s error to any error implementing From
for
this future’s Error
, returning a new future.
sourcefn then<F, B>(self, f: F) -> Then<Self, B, F>where
F: FnOnce(Result<Self::Item, Self::Error>, &mut Self::Actor, &mut <Self::Actor as Actor>::Context) -> B,
B: IntoActorFuture<Actor = Self::Actor>,
Self: Sized,
fn then<F, B>(self, f: F) -> Then<Self, B, F>where
F: FnOnce(Result<Self::Item, Self::Error>, &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
.