Struct message_io::node::NodeListener [−][src]
Main entity to manipulates the network and signal events easily. The node run asynchronously.
Implementations
impl<S: Send + 'static> NodeListener<S>
[src]
pub fn for_each(self, event_callback: impl FnMut(NodeEvent<'_, S>) + 'static)
[src]
Iterate indefinitely over all generated NetEvent
.
This function will work until NodeHandler::stop
was called.
Note that any events generated before calling this function (e.g. some connection was done)
will be storage and offered once you call for_each()
.
Example
use message_io::node::{self, NodeEvent}; use message_io::network::Transport; let (handler, listener) = node::split(); handler.signals().send_with_timer((), std::time::Duration::from_secs(1)); handler.network().listen(Transport::FramedTcp, "0.0.0.0:1234"); listener.for_each(move |event| match event { NodeEvent::Network(net_event) => { /* Your logic here */ }, NodeEvent::Signal(_) => handler.stop(), }); // Blocked here until handler.stop() was called (1 sec). println!("Node is stopped");
pub fn for_each_async(
self,
event_callback: impl FnMut(NodeEvent<'_, S>) + Send + 'static
) -> NodeTask
[src]
self,
event_callback: impl FnMut(NodeEvent<'_, S>) + Send + 'static
) -> NodeTask
Similar to NodeListener::for_each()
but it returns the control to the user
after call it. The events would be processed asynchronously.
A NodeTask
representing this asynchronous job is returned.
Destroying this object will result in blocking the current thread until
NodeHandler::stop
was called.
In order to allow the node working asynchronously, you can move the NodeTask
to a
an object with a longer lifetime.
use message_io::node::{self, NodeEvent}; use message_io::network::Transport; let (handler, listener) = node::split(); handler.signals().send_with_timer((), std::time::Duration::from_secs(1)); handler.network().listen(Transport::FramedTcp, "0.0.0.0:1234"); let task = listener.for_each(move |event| match event { NodeEvent::Network(net_event) => { /* Your logic here */ }, NodeEvent::Signal(_) => handler.stop(), }); // for_each_async() will act asynchronous during 'task' lifetime. // ... println!("Node is running"); // ... drop(task); // Blocked here until handler.stop() was called (1 sec). // Also task.wait(); can be called doing the same (but taking a mutable reference). println!("Node is stopped");
Trait Implementations
Auto Trait Implementations
impl<S> !RefUnwindSafe for NodeListener<S>
impl<S> Send for NodeListener<S>
impl<S> Sync for NodeListener<S> where
S: Sync,
S: Sync,
impl<S> Unpin for NodeListener<S> where
S: Unpin,
S: Unpin,
impl<S> !UnwindSafe for NodeListener<S>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,