Crate async_events_emitter
source ·Expand description
Event Emitter Library
async-events-emitter
is a Rust library providing an implementation of an event handling system.
It allows users to define custom events and handlers, and emit events that are processed asynchronously.
Usage
use async_events_emitter::*;
use async_trait::async_trait;
// Define your events
#[derive(Debug, Clone)]
struct MyEvent;
// Impl the EventHandler trait
#[async_trait]
impl EventHandler<MyEvent> for MyHandler {
async fn handle_event(&self, event: MyEvent) {
// TODO: Process and handle your event async
}
}
let ee = EventEmitter::new();
// Init the handler
let handler = EventHandler;
// Attach the handler to your event
ee.on::<MyEvent>(handler);
// Now emit the event
ee.emit(MyEvent);
Features
- Define custom events.
- Register asynchronous event handlers.
- Emit events to be handled by registered handlers.
Structs
- The
EventEmitter
struct is the core of the event handling system. It allows registration of event handlers and emits events to these handlers.