You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* use uuid as listener_id instead of a string
* fmt cargo.toml & ignore bacon files
* relax trait bounds on emit method
* add extra utils methods and map listener map private
* update deps
* add global_listener for all events
* fix format check in ci
* update documentation
* add a test for global listener
Copy file name to clipboardExpand all lines: README.md
+15-1Lines changed: 15 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Events are in the form of (strings, value) and callbacks are in the form of clos
14
14
#### Differences between this crate and [`event-emitter-rs`](https://crates.io/crates/event-emitter-rs)
15
15
- This is an async implementation that works for all common async runtimes (Tokio, async-std and smol)
16
16
- The listener methods ***(on and once)*** take a callback that returns a future instead of a merely a closure.
17
-
- The emit methods executes each callback on each event by spawning a tokio task instead of a std::thread
17
+
- The emit methods executes each callback on each event by spawning intra-task instead of a std::thread.
18
18
- This emitter is thread safe and can also be used lock-free (supports interior mutability).
19
19
20
20
***Note***: To use strict return and event types, use [typed-emitter](https://crates.io/crates/typed-emitter), that crate solves [this issue](https://github.com/spencerjibz/async-event-emitter-rs/issues/31) too.
@@ -103,7 +103,21 @@ Removing listeners is also easy
103
103
None=>println!("No event listener of that id exists"),
104
104
}
105
105
```
106
+
Listening to all emitted events with a single listener
## Differences between this crate and [`event-emitter-rs`](https://crates.io/crates/event-emitter-rs)
9
9
- This is an async implementation that works for all common async runtimes (Tokio, async-std and smol)
10
10
- The listener methods ***(on and once)*** take a callback that returns a future instead of a merely a closure.
11
-
- The emit methods executes each callback on each event by spawning a tokio task instead of a std::thread
11
+
- The emit methods executes each callback on each event by running async intra-task instead of spawning a std::thread
12
12
- This emitter is thread safe and can also be used lock-free (supports interior mutability).
13
13
14
-
15
14
***Note***: To use strict return and event types, use [typed-emitter](https://crates.io/crates/typed-emitter), that crate solves [this issue](https://github.com/spencerjibz/async-event-emitter-rs/issues/31) too.
16
15
17
16
## Getting Started
@@ -70,11 +69,28 @@
70
69
let event_emitter = EventEmitter::new();
71
70
72
71
let listener_id = event_emitter.on("Hello", |_: ()| async {println!("Hello World")});
73
-
match event_emitter.remove_listener(&listener_id) {
72
+
match event_emitter.remove_listener(listener_id) {
/// Emits an event of the given parameters and executes each callback that is listening to that event asynchronously by spawning a task for each callback.
0 commit comments