Function message_worker::non_blocking::listen [−][src]
pub fn listen<Ctx, CtxFactory, Source, Message, HandleMessageFuture, HandleMessageErrorT>(
source: Source,
context_factory: CtxFactory,
handle_message: fn(_: Arc<Ctx>, _: Message) -> HandleMessageFuture
) -> JoinHandle<()> where
Ctx: Send + Sync + 'static,
CtxFactory: FnOnce() -> Ctx + Send + 'static,
Source: Stream<Item = Message> + Unpin + Send + 'static,
Message: Send + 'static,
HandleMessageFuture: Future<Output = Result<Option<Ctx>, HandleMessageErrorT>> + Send + 'static,
HandleMessageErrorT: Into<Error> + Send,
Expand description
Creates a listener with the default error handler on its own system thread. It is safe to work
with non-sync and non-send data in this listener. The callback (handle_message
) will be invoked
whenever a new item from the source
stream is emitted. The context_factory
is a closure you
must provide that returns the initial state for the listener.