|
|
@ -148,9 +148,8 @@ impl VentedServer {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Adds a handler for the given event.
|
|
|
|
/// Adds a handler for the given event.
|
|
|
|
/// The event returned by the handler is returned to the server.
|
|
|
|
/// The event returned by the handler is returned to the sender.
|
|
|
|
/// If there is more than one handler, the response will be piped to the next handler.
|
|
|
|
/// Multiple handlers can be registered for an event.
|
|
|
|
/// The oder is by order of insertion. The first registered handler will be executed first.
|
|
|
|
|
|
|
|
pub fn on<F: 'static>(&mut self, event_name: &str, handler: F)
|
|
|
|
pub fn on<F: 'static>(&mut self, event_name: &str, handler: F)
|
|
|
|
where
|
|
|
|
where
|
|
|
|
F: Fn(Event) -> Option<Event> + Send + Sync,
|
|
|
|
F: Fn(Event) -> Option<Event> + Send + Sync,
|
|
|
@ -299,7 +298,7 @@ impl VentedServer {
|
|
|
|
) -> VentedResult<()> {
|
|
|
|
) -> VentedResult<()> {
|
|
|
|
while let Ok(mut event) = stream.read() {
|
|
|
|
while let Ok(mut event) = stream.read() {
|
|
|
|
event.origin = Some(stream.receiver_node().clone());
|
|
|
|
event.origin = Some(stream.receiver_node().clone());
|
|
|
|
if let Some(response) = event_handler.lock().handle_event(event) {
|
|
|
|
for response in event_handler.lock().handle_event(event) {
|
|
|
|
stream.send(response)?
|
|
|
|
stream.send(response)?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|