2 unstable releases

0.1.0 Dec 20, 2023
0.0.1 Dec 19, 2023

#960 in Asynchronous

MIT license

11KB
228 lines

Epicenter

Simple sync/async event dispatcher for Rust

crates.io download count badge docs.rs

Usage

use epicenter::{Event, AsyncDispatcher};

#[derive(Debug, Clone)]
struct ExampleEvent {}
impl Event for ExampleEvent {}

let mut dispatcher = AsyncDispatcher::new();

dispatcher.listen(|event: ExampleEvent| async move {
    // ...
}).await;

dispatcher.dispatch(&ExampleEvent {}).await?;

Refer to the documentation on docs.rs for detailed usage instructions.

License

This project is licensed under the MIT License - see the LICENSE file for details.


lib.rs:

A simple sync/async event dispatcher.

Usage

use epicenter::{Event, AsyncDispatcher};

struct OrderShipped {
    order_id: u64
}
impl Event for OrderShipped {}

let mut dispatcher = AsyncDispatcher::new();

dispatcher.listen(|event: OrderShipped| async move {
    assert_eq!(event.order_id, 123);
}).await;

dispatcher.dispatch(&OrderShipped { order_id: 123 }).await?;

Dependencies

~0.2–6.5MB
~38K SLoC