eventbus-tiny
Welcome to eventbus-tiny 🎉
eventbus-tiny is a small, dependency-free, no-unsafe crate that provides a multi-producer broadcast-consumer event
bus for arbitrary event types (as long as they are Send).
Implementation and Locking
The implementation nearly lock-free, only requiring a write-lock if the registry changes (i.e. if a new subscriber is
added, or shrink_to_fit is called) - everything else uses either a cooperative read-lock, or is completely lockfree
via the underlying [std::sync::mpsc]-channels.
This approach provides a reasonable compromise between ease-of-implementation (no dependencies, no unsafe code,
well-known semantics of built-in types), and performance with lock-free operation in all critical hot-zones like event
publication and awaiting/receiving events.
Example
use EventBus;
use Subscription;
// Create bus and subscribers
let bus = new;
let subscriber_a: = bus.subscribe;
let subscriber_b: = bus.subscribe;
// Publish some events and ensure they get delivered to all two subscribers
assert_eq!;
assert_eq!;
assert_eq!;
// Receive events
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// Drop bus and assert the subscribers are dead
drop;
assert!;
assert!;