Crates.io | event-source |
lib.rs | event-source |
version | 0.4.2 |
source | src |
created_at | 2023-09-06 03:08:26.485034 |
updated_at | 2023-09-09 14:27:22.978459 |
description | Zero cost async immediate event dispatching |
homepage | |
repository | https://github.com/storycraft/event-source |
max_upload_size | |
id | 964982 |
size | 23,270 |
Zero cost non buffered async event emitter
This crate is no_std
async fn main() {
let source: Arc<EventSource!(&mut i32)> = Arc::new(EventSource::new());
// imaginary function for spawning future in another thread
spawn({
let source = source.clone();
async {
let mut a = 35;
emit!(source, &mut a);
}
});
let mut output = 0;
// Closure can contain reference!
source.on(|value, flow| {
println!("Event emiited with value: {}!", value);
output = *value;
// mark listener as finished
flow.set_done();
}).await;
println!("Output: {}", output);
}
Output
Event emiited with value: 35!
Output: 35
MIT