Trait actix::prelude::actix::AsyncContext
[−]
[src]
pub trait AsyncContext<A>: ActorContext + ToEnvelope<A> where
A: Actor<Context = Self>, { fn spawn<F>(&mut self, fut: F) -> SpawnHandle
where
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static; fn wait<F>(&mut self, fut: F)
where
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static; fn cancel_future(&mut self, handle: SpawnHandle) -> bool; fn address<Address>(&mut self) -> Address
where
A: ActorAddress<A, Address>, { ... } fn add_future<F>(&mut self, fut: F)
where
F: Future + 'static,
F::Item: ResponseType,
A: Handler<Result<F::Item, F::Error>>, { ... } fn add_stream<S>(&mut self, fut: S)
where
S: Stream + 'static,
S::Item: ResponseType,
A: StreamHandler<Result<S::Item, S::Error>>, { ... } fn add_message_stream<S>(&mut self, fut: S)
where
S: Stream<Error = ()> + 'static,
S::Item: ResponseType,
A: StreamHandler<S::Item>, { ... } fn notify<M>(&mut self, msg: M)
where
A: Handler<M>,
M: ResponseType + 'static, { ... } fn notify_later<M>(&mut self, msg: M, after: Duration) -> SpawnHandle
where
A: Handler<M>,
M: ResponseType + 'static, { ... } fn run_later<F>(&mut self, dur: Duration, f: F) -> SpawnHandle
where
F: FnOnce(&mut A, &mut A::Context) + 'static, { ... } }
Asynchronous execution context
Required Methods
fn spawn<F>(&mut self, fut: F) -> SpawnHandle where
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static,
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static,
Spawn async future into context. Returns handle of the item, could be used for cancelling execution.
fn wait<F>(&mut self, fut: F) where
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static,
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static,
Spawn future into the context. Stop processing any of incoming events until this future resolves.
fn cancel_future(&mut self, handle: SpawnHandle) -> bool
Cancel future. idx is a value returned by spawn
method.
Provided Methods
fn address<Address>(&mut self) -> Address where
A: ActorAddress<A, Address>,
A: ActorAddress<A, Address>,
Get actor address
fn add_future<F>(&mut self, fut: F) where
F: Future + 'static,
F::Item: ResponseType,
A: Handler<Result<F::Item, F::Error>>,
F: Future + 'static,
F::Item: ResponseType,
A: Handler<Result<F::Item, F::Error>>,
This method allow to handle Future in similar way as normal actor messages.
use actix::prelude::*; #[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>) { // send `Ping` to self. ctx.notify(Ping); } }
fn add_stream<S>(&mut self, fut: S) where
S: Stream + 'static,
S::Item: ResponseType,
A: StreamHandler<Result<S::Item, S::Error>>,
S: Stream + 'static,
S::Item: ResponseType,
A: StreamHandler<Result<S::Item, S::Error>>,
This method is similar to add_future
but works with streams.
Information to consider. Actor wont receive next item from a stream
until Response
future resolves to result. Self::reply
and
Self::reply_error
resolves immediately.
fn add_message_stream<S>(&mut self, fut: S) where
S: Stream<Error = ()> + 'static,
S::Item: ResponseType,
A: StreamHandler<S::Item>,
S: Stream<Error = ()> + 'static,
S::Item: ResponseType,
A: StreamHandler<S::Item>,
This method is similar to add_stream
but it skips errors.
fn notify<M>(&mut self, msg: M) where
A: Handler<M>,
M: ResponseType + 'static,
A: Handler<M>,
M: ResponseType + 'static,
Send message msg
to self.
fn notify_later<M>(&mut self, msg: M, after: Duration) -> SpawnHandle where
A: Handler<M>,
M: ResponseType + 'static,
A: Handler<M>,
M: ResponseType + 'static,
Send message msg
to self after specified period of time. Returns spawn handle
which could be used for cancelation. Notification get cancelled
if context's stop method get 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,
Execute closure after specified period of time within same Actor and Context Execution get cancelled if context's stop method get called.
Implementors
impl<A> AsyncContext<A> for Context<A> where
A: Actor<Context = Self>,impl<A> AsyncContext<A> for FramedContext<A> where
A: Actor<Context = Self> + FramedActor,