[−][src]Trait actix::AsyncContext
Asynchronous execution context.
Required methods
fn address(&self) -> Addr<A>
Returns the address of the context.
fn spawn<F>(&mut self, fut: F) -> SpawnHandle where
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static,
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static,
Spawns a future into the context.
Returns a handle of the spawned future, which can be used for cancelling its execution.
All futures spawned into an actor's context are cancelled during the actor's stopping stage.
fn wait<F>(&mut self, fut: F) where
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static,
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static,
Spawns a future into the context, waiting for it to resolve.
This stops processing any incoming events until the future resolves.
fn waiting(&self) -> bool
Checks if the context is paused (waiting for future completion or stopping).
fn cancel_future(&mut self, handle: SpawnHandle) -> bool
Cancels a spawned future.
The handle
is a value returned by the spawn
method.
Provided methods
fn add_stream<S>(&mut self, fut: S) -> SpawnHandle where
S: Stream + 'static,
A: StreamHandler<S::Item, S::Error>,
S: Stream + 'static,
A: StreamHandler<S::Item, S::Error>,
Registers a stream with the context.
This allows handling a Stream
in a way similar to normal
actor messages.
use actix::prelude::*; use futures::stream::once; #[derive(Message)] struct Ping; struct MyActor; impl StreamHandler<Ping, io::Error> for MyActor { fn handle(&mut self, item: Ping, ctx: &mut Context<MyActor>) { println!("PING"); } fn finished(&mut self, ctx: &mut Self::Context) { println!("finished"); } } impl Actor for MyActor { type Context = Context<Self>; fn started(&mut self, ctx: &mut Context<Self>) { // add stream ctx.add_stream(once::<Ping, io::Error>(Ok(Ping))); } }
fn add_message_stream<S>(&mut self, fut: S) where
S: Stream<Error = ()> + 'static,
S::Item: Message,
A: Handler<S::Item>,
S: Stream<Error = ()> + 'static,
S::Item: Message,
A: Handler<S::Item>,
Registers a stream with the context, ignoring errors.
This method is similar to add_stream
but it skips stream
errors.
use actix::prelude::*; use futures::stream::once; #[derive(Message)] struct Ping; struct MyActor; impl Handler<Ping> for MyActor { type Result = (); fn handle(&mut self, msg: Ping, ctx: &mut Context<MyActor>) { println!("PING"); } } impl Actor for MyActor { type Context = Context<Self>; fn started(&mut self, ctx: &mut Context<Self>) { // add messages stream ctx.add_message_stream(once(Ok(Ping))); } }
fn notify<M>(&mut self, msg: M) where
A: Handler<M>,
M: Message + 'static,
A: Handler<M>,
M: Message + 'static,
Sends the message msg
to self.
fn notify_later<M>(&mut self, msg: M, after: Duration) -> SpawnHandle where
A: Handler<M>,
M: Message + 'static,
A: Handler<M>,
M: Message + 'static,
Sends the message msg
to self after a specified period of time.
Returns a spawn handle which can be used for cancellation. The notification gets cancelled if the context's stop method gets called.
fn run_later<F>(&mut self, dur: Duration, f: F) -> SpawnHandle where
F: FnOnce(&mut A, &mut A::Context) + 'static,
F: FnOnce(&mut A, &mut A::Context) + 'static,
Executes a closure after a specified period of time.
The closure gets passed the same actor and its context. Execution gets cancelled if the context's stop method gets called.
fn run_interval<F>(&mut self, dur: Duration, f: F) -> SpawnHandle where
F: FnMut(&mut A, &mut A::Context) + 'static,
F: FnMut(&mut A, &mut A::Context) + 'static,
Spawns a job to execute the given closure periodically, at a specified fixed interval.
Implementors
impl<A> AsyncContext<A> for Context<A> where
A: Actor<Context = Self>,
[src]
impl<A> AsyncContext<A> for Context<A> where
A: Actor<Context = Self>,
fn spawn<F>(&mut self, fut: F) -> SpawnHandle where | [src] |
fn wait<F>(&mut self, fut: F) where | [src] |
fn waiting(&self) -> bool | [src] |
fn cancel_future(&mut self, handle: SpawnHandle) -> bool | [src] |
fn address(&self) -> Addr<A> | [src] |
fn add_stream<S>(&mut self, fut: S) -> SpawnHandle where | [src] |
fn add_message_stream<S>(&mut self, fut: S) where | [src] |
fn notify<M>(&mut self, msg: M) where | [src] |
fn notify_later<M>(&mut self, msg: M, after: Duration) -> SpawnHandle where | [src] |
fn run_later<F>(&mut self, dur: Duration, f: F) -> SpawnHandle where | [src] |
fn run_interval<F>(&mut self, dur: Duration, f: F) -> SpawnHandle where | [src] |