Module reactive_mutiny::multi
source · Expand description
Allows creating multis, which represent pairs of (producer, event pipeline) that may be used to
produce() asynchronous payloads to be processed by a multiple event pipeline Streams – and executed
by async tasks.
Usage:
fn local_on_event(stream: impl Stream<Item=String>) -> impl Stream<Item=Arc<String>> {
stream.inspect(|message| println!("To Zeta: '{}'", message))
}
fn zeta_on_event(stream: impl Stream<Item=String>) -> impl Stream<Item=Arc<String>> {
stream.inspect(|message| println!("ZETA: Received a message: '{}'", message))
}
fn earth_on_event(stream: impl Stream<Item=String>) -> impl Stream<Item=Arc<String>> {
stream.inspect(|sneak_peeked_message| println!("EARTH: Sneak peeked a message to Zeta Reticuli: '{}'", sneak_peeked_message))
}
let multi = MultiBuilder::new()
.on_stream_close(|_| async {})
.into_executable()
.spawn_non_futures_non_fallible_executor("doc_test() local onEvent()", local_on_event).await
.spawn_non_futures_non_fallible_executor("doc_test() zeta onEvent()", zeta_on_event).await
.spawn_non_futures_non_fallible_executor("doc_test() earth onEvent()", earth_on_event).await
.handle();
let producer = multi.producer_closure();
producer("I've just arrived!".to_string()).await;
producer("Nothing really interesting here... heading back home!".to_string()).await;
multi.close().await;
Re-exports
pub use crate::types::ChannelCommon;
Modules
- Provides channels to be used in Unis
Macros
- Macro to close, atomically-ish, all Multis passed in as parameters
Structs
- Keeps track of the
stream_executorassociated to eachstream_id Multiis an event handler capable of having several “listeners” – all of which receives all events.
With this struct, it is possible to: