Crates.io | async-events-emitter |
lib.rs | async-events-emitter |
version | 0.1.0 |
source | src |
created_at | 2024-01-15 10:47:40.973981 |
updated_at | 2024-01-15 10:47:40.973981 |
description | Library providing an implementation of an event handling system |
homepage | |
repository | |
max_upload_size | |
id | 1100225 |
size | 36,467 |
async-events-emitter
is a Rust library providing an asynchronous event handling system. It allows users to define custom events and handlers, emit events, and process them asynchronously.
Add async-events-emitter
to your Cargo.toml
:
[dependencies]
async-events-emitter = "0.1.0
Here's a quick example to get you started:
use async_events_emitter::*;
use async_trait::async_trait;
// Define your custom event
#[derive(Debug, Clone)]
struct MyEvent;
// Implement the EventHandler trait
#[async_trait]
impl EventHandler<MyEvent> for MyHandler {
async fn handle_event(&self, event: MyEvent) {
// Process and handle your event asynchronously
}
}
// Usage
#[tokio::main]
async fn main() {
let mut ee = EventEmitter::new();
let handler = MyHandler;
// Attach the handler to your event
ee.on::<MyEvent>(handler);
// Emit the event
ee.emit(MyEvent);
}
This library is distributed under the terms of Apache-2.0. See LICENSE for details.
Created with </>
by Amit Shmulevitch.