Function message_io::node::split [−][src]
pub fn split<S: Send>() -> (NodeHandler<S>, NodeListener<S>)
Creates a node already working.
This function offers two instances: a NodeHandler to perform network and signals actions
and a NodeListener to receive the events the node receives.
Note that NodeListener is already listen for events from its creation.
In order to get the listened events you can call NodeListener::for_each()
Any event happened before for_each() call will be also dispatched.
Examples
use message_io::node::{self, NodeEvent}; enum Signal { Close, Tick, //Other signals here. } let (handler, listener) = node::split(); handler.signals().send_with_timer(Signal::Close, std::time::Duration::from_secs(1)); listener.for_each(move |event| match event { NodeEvent::Network(_) => { /* ... */ }, NodeEvent::Signal(signal) => match signal { Signal::Close => handler.stop(), //Received after 1 sec Signal::Tick => { /* ... */ }, }, });
In case you don’t use signals, specify the node type with an unit (()) type.
use message_io::node::{self}; let (handler, listener) = node::split::<()>();