#events #event-system #parallel

concurrent-event

An event system which invokes event handlers concurrently

1 unstable release

0.1.0 Jul 5, 2020

#29 in #event-system

MIT/Apache

15KB
206 lines

concurrent-event

An event system for Rust which invokes event handlers in parallel.


lib.rs:

This crate implements an event which executes registered event handlers concurrently. Additionally, each handler is assigned an ID with which it can be referenced after creation. This allows for associated state for each event handler.

The system was setup to be resistant to adversarial code. In particular, IDs are assigned randomly with sufficiently many bits to be unfeasable to guess. As a consequence, efficiency may suffer. Particularly the IDs are larger than they would need to be if assigned sequentially.

Important Note

We provide no guarantees as the security properties were not rigorously verified. Do not use in critical systems without further investigation!

Example

This is a simple usage scenarion with a custom event handler.

use concurrent_event::Event;
use concurrent_event::handler::EventHandler; 

struct Printer;

impl EventHandler<&str> for Printer {
    fn on_event(&mut self, arg: &str) {
        print!("{}", arg);
    }
}

let mut event = Event::<&str, Printer>::new();
event.emit("Hello, World!");

In the handler package, default implementation for stateless and stateful event handlers can be found, which take a closure at construction.

Dependencies

~1MB
~15K SLoC