A thread-safe, asynchronous event system for Rust.
Ewait allows the creation of events that can trigger multiple callbacks parallely, making it easier to build event-based code.
- Every connected callback runs in its own Tokio task, allowing parallel execution.
- Provides easy methods to connect, disconnect, and fire events.
- Conveniently provides a
JoinHandle<R>to.awaitresults to if the results are of interest. - Automatically manages the distribution of Arc references between threads.
Simply run cargo add ewait in the desired Rust project.
Here is an example on how to use the Event struct:
use tokio;
use ewait::Event;
use std::sync::Arc;
async fn hello(_: Arc<()>) {
println!("Hello World!")
}
#[tokio::main]
async fn main() {
let mut event1: Event<()> = Event::new();
event1.connect(hello);
event1.fire(());
}Warning
This library requires a Tokio runtime to function. Make sure your main function uses #[tokio::main].
Caution
This project is developed by a new Rustacean. The testing is limited.