Trait actix::fut::future::ActorFutureExt
source · pub trait ActorFutureExt<A: Actor>: ActorFuture<A> {
// Provided methods
fn map<F, U>(self, f: F) -> Map<Self, F>
where F: FnOnce(Self::Output, &mut A, &mut A::Context) -> U,
Self: Sized { ... }
fn then<F, Fut>(self, f: F) -> Then<Self, Fut, F>
where F: FnOnce(Self::Output, &mut A, &mut A::Context) -> Fut,
Fut: ActorFuture<A>,
Self: Sized { ... }
fn timeout(self, timeout: Duration) -> Timeout<Self>
where Self: Sized { ... }
fn boxed_local(self) -> LocalBoxActorFuture<A, Self::Output>
where Self: Sized + 'static { ... }
}
Provided Methods§
sourcefn map<F, U>(self, f: F) -> Map<Self, F>
fn map<F, U>(self, f: F) -> Map<Self, F>
Map this future’s result to a different type, returning a new future of the resulting type.
sourcefn then<F, Fut>(self, f: F) -> Then<Self, Fut, F>
fn then<F, Fut>(self, f: F) -> Then<Self, Fut, F>
Chain on a computation for when a future finished, passing the result of
the future to the provided closure f
.
Examples found in repository?
More examples
examples/weak_recipient.rs (line 91)
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
fn started(&mut self, ctx: &mut Self::Context) {
println!("🐰 starting ClientA");
TimeService::from_registry()
.send(RegisterForTime(ctx.address().downgrade().recipient()))
.into_actor(self)
.then(|_, _slf, _| fut::ready(()))
.spawn(ctx);
}
fn stopping(&mut self, _ctx: &mut Self::Context) -> Running {
println!("🐰 stopping ClientA");
Running::Stop
}
fn stopped(&mut self, _ctx: &mut Self::Context) {
println!("🐰 stopped ClientA");
}
}
impl Handler<TimePing> for ClientA {
type Result = ();
fn handle(&mut self, msg: TimePing, _ctx: &mut Self::Context) -> Self::Result {
println!("🐰 ClientA received ping: {:?}", msg.0);
}
}
#[derive(Debug, Default)]
pub struct ClientB;
impl Actor for ClientB {
type Context = Context<Self>;
fn started(&mut self, ctx: &mut Self::Context) {
println!("🐇 starting ClientB");
TimeService::from_registry()
.send(RegisterForTime(ctx.address().downgrade().recipient()))
.into_actor(self)
.then(|_, _slf, _| fut::ready(()))
.spawn(ctx);
}
sourcefn timeout(self, timeout: Duration) -> Timeout<Self>where
Self: Sized,
fn timeout(self, timeout: Duration) -> Timeout<Self>where
Self: Sized,
Add timeout to futures chain.
Err(())
returned as a timeout error.
sourcefn boxed_local(self) -> LocalBoxActorFuture<A, Self::Output>where
Self: Sized + 'static,
fn boxed_local(self) -> LocalBoxActorFuture<A, Self::Output>where
Self: Sized + 'static,
Wrap the future in a Box, pinning it.
A shortcut for wrapping in Box::pin
.