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 dashmap and enable interior mutability
* remove debug trait requirement
* add support for other async-runtimes without feature flags
clean up dep tree too
* fix code coverage ci
Copy file name to clipboardExpand all lines: README.md
+13-21Lines changed: 13 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,19 +12,20 @@ Allows you to subscribe to events with callbacks and also fire those events.
12
12
Events are in the form of (strings, value) and callbacks are in the form of closures that take in a value parameter;
13
13
14
14
#### Differences between this crate and [`event-emitter-rs`](https://crates.io/crates/event-emitter-rs)
15
+
- This is an async implementation that works for all common async runtimes (Tokio, async-std and smol)
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
18
+
- This emitter is thread safe and can also be used lock-free (supports interior mutability).
15
19
16
-
- Emitted values should implement an extra trait (Debug) in addition to Serde's Serialize and Deserialize.
17
-
- This is an async implementation, not limited to tokio, but async-std is supported under the ``` use-async-std ``` feature flag.
18
-
- The listener methods **_(on and once)_** take a callback that returns a future instead of a merely a closure.
19
-
- The emit methods executes each callback on each event by spawning a tokio task instead of a std::thread
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.
20
21
21
22
#### Getting Started
22
23
23
24
```rust
24
25
useasync_event_emitter::AsyncEventEmitter;
25
26
#[tokio::main]
26
27
asyncfnmain() {
27
-
letmutevent_emitter=AsyncEventEmitter::new();
28
+
letevent_emitter=AsyncEventEmitter::new();
28
29
// This will print <"Hello world!"> whenever the <"Say Hello"> event is emitted
Tokio is the default runtime for this library but async-std support can be able enabled by disabling default-features on the crate and enabling the ```use-async-std``` feature.
147
-
<br>
148
-
**Note**: Use simply replace tokio::main with async-std::main and tokio::test with async-std::test (provided you've enabled the "attributes" feature on the crate.
139
+
#### Usage with other runtimes
140
+
Check out the examples from the [typed version of this crate](https://docs.rs/typed-emitter/0.1.2/typed_emitter/#getting-started), just replace the emntter type.
149
141
150
142
#### Testing
151
143
Run the tests on this crate with all-features enabled as follows:
0 commit comments