Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/storycraft/event-source
Zero cost non buffered async event emitter
https://github.com/storycraft/event-source
Last synced: 3 months ago
JSON representation
Zero cost non buffered async event emitter
- Host: GitHub
- URL: https://github.com/storycraft/event-source
- Owner: storycraft
- Created: 2023-09-03T07:04:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-09T14:26:35.000Z (over 1 year ago)
- Last Synced: 2024-10-03T08:45:54.255Z (3 months ago)
- Language: Rust
- Homepage:
- Size: 60.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# EventSource
Zero cost non buffered async event emitterThis crate is no_std
## Features
1. Non buffered, immediate event dispatch
2. Zero cost listener adding, removing
3. Higher kinded event type
4. Propagation control## Example
```rust ignore
async fn main() {
let source: Arc = 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
```text
Event emiited with value: 35!
Output: 35
```## License
MIT