[−][src]Trait actix::AsyncContext
Asynchronous execution context.
Required methods
pub fn address(&self) -> Addr<A>
[src]
Returns the address of the context.
pub fn spawn<F>(&mut self, fut: F) -> SpawnHandle where
F: ActorFuture<Output = (), Actor = A> + 'static,
[src]
F: ActorFuture<Output = (), 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.
pub fn wait<F>(&mut self, fut: F) where
F: ActorFuture<Output = (), Actor = A> + 'static,
[src]
F: ActorFuture<Output = (), Actor = A> + 'static,
Spawns a future into the context, waiting for it to resolve.
This stops processing any incoming events until the future resolves.
pub fn waiting(&self) -> bool
[src]
Checks if the context is paused (waiting for future completion or stopping).
pub fn cancel_future(&mut self, handle: SpawnHandle) -> bool
[src]
Cancels a spawned future.
The handle
is a value returned by the spawn
method.
Provided methods
pub fn add_stream<S>(&mut self, fut: S) -> SpawnHandle where
S: Stream + 'static,
A: StreamHandler<S::Item>,
[src]
S: Stream + 'static,
A: StreamHandler<S::Item>,
Registers a stream with the context.
This allows handling a Stream
in a way similar to normal
actor messages.
use actix::prelude::*; use futures_util::stream::once; #[derive(Message)] #[rtype(result = "()")] struct Ping; struct MyActor; impl StreamHandler<Ping> for MyActor { fn handle(&mut self, item: Ping, ctx: &mut Context<MyActor>) { println!("PING"); System::current().stop(); } 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(async { Ping })); } } fn main() { let mut sys = System::new("example"); let addr = sys.block_on(async { MyActor.start() }); sys.run(); }
pub fn add_message_stream<S>(&mut self, fut: S) where
S: Stream + 'static,
S::Item: Message,
A: Handler<S::Item>,
[src]
S: Stream + '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_util::stream::once; #[derive(Message)] #[rtype(result = "()")] 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(async { Ping })); } } fn main() { System::run(|| { let addr = MyActor.start(); }); }
pub fn notify<M>(&mut self, msg: M) where
A: Handler<M>,
M: Message + 'static,
[src]
A: Handler<M>,
M: Message + 'static,
Sends the message msg
to self. This bypasses the mailbox capacity, and
will always queue the message. If the actor is in the stopped
state, an
error will be raised.
pub fn notify_later<M>(&mut self, msg: M, after: Duration) -> SpawnHandle where
A: Handler<M>,
M: Message + 'static,
[src]
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. This bypasses the mailbox capacity, and
will always queue the message. If the actor is in the stopped
state, an
error will be raised.
pub fn run_later<F>(&mut self, dur: Duration, f: F) -> SpawnHandle where
F: FnOnce(&mut A, &mut A::Context) + 'static,
[src]
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.
pub fn run_interval<F>(&mut self, dur: Duration, f: F) -> SpawnHandle where
F: FnMut(&mut A, &mut A::Context) + 'static,
[src]
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]
A: Actor<Context = Self>,
pub fn spawn<F>(&mut self, fut: F) -> SpawnHandle where
F: ActorFuture<Output = (), Actor = A> + 'static,
[src]
F: ActorFuture<Output = (), Actor = A> + 'static,
pub fn wait<F>(&mut self, fut: F) where
F: ActorFuture<Output = (), Actor = A> + 'static,
[src]
F: ActorFuture<Output = (), Actor = A> + 'static,