Trait actix::prelude::StreamHandler
[−]
[src]
pub trait StreamHandler<I, E> where
Self: Actor, { fn handle(&mut self, item: I, ctx: &mut Self::Context); fn started(&mut self, ctx: &mut Self::Context) { ... } fn error(&mut self, err: E, ctx: &mut Self::Context) -> Running { ... } fn finished(&mut self, ctx: &mut Self::Context) { ... } fn add_stream<S>(fut: S, ctx: &mut Self::Context) -> SpawnHandle
where
Self::Context: AsyncContext<Self>,
S: Stream<Item = I, Error = E> + 'static,
I: 'static,
E: 'static, { ... } }
Stream handler
Required Methods
fn handle(&mut self, item: I, ctx: &mut Self::Context)
Method is called for every message received by this Actor
Provided Methods
fn started(&mut self, ctx: &mut Self::Context)
Method is called when stream get polled first time.
fn error(&mut self, err: E, ctx: &mut Self::Context) -> Running
Method is called when stream emits error.
If this method returns ErrorAction::Continue
stream processing continues
otherwise stream processing stops. Default method
implementation returns ErrorAction::Stop
fn finished(&mut self, ctx: &mut Self::Context)
Method is called when stream finishes.
By default this method stops actor execution.
fn add_stream<S>(fut: S, ctx: &mut Self::Context) -> SpawnHandle where
Self::Context: AsyncContext<Self>,
S: Stream<Item = I, Error = E> + 'static,
I: 'static,
E: 'static,
Self::Context: AsyncContext<Self>,
S: Stream<Item = I, Error = E> + 'static,
I: 'static,
E: 'static,
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 a result. Self::reply
resolves immediately.
This method is similar to add_stream
but it skips result error.
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 Self::add_stream(once::<Ping, io::Error>(Ok(Ping)), ctx); } }