No description
Find a file
dependabot[bot] 5414b798dc
chore(deps): bump tokio from 1.48.0 to 1.49.0 (#15)
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.48.0 to 1.49.0.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.48.0...tokio-1.49.0)

---
updated-dependencies:
- dependency-name: tokio
  dependency-version: 1.49.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-01 19:36:11 +01:00
.github update rust version & nextest installation 2026-03-01 19:27:24 +01:00
src chore: fix a clippy issue 2026-03-01 19:02:38 +01:00
.gitignore first commit 2025-11-27 15:37:17 +01:00
Cargo.lock chore(deps): bump tokio from 1.48.0 to 1.49.0 (#15) 2026-03-01 19:36:11 +01:00
Cargo.toml chore(deps): bump test-strategy from 0.4.3 to 0.4.5 (#19) 2026-03-01 19:35:41 +01:00
CHANGELOG.md chore: release v0.1.6 (#13) 2025-12-05 03:11:41 +01:00
deny.toml chore: update cargo-deny version 2026-03-01 19:15:10 +01:00
LICENSE first commit 2025-11-27 15:37:17 +01:00
Makefile.toml first commit 2025-11-27 15:37:17 +01:00
README.md Update README.md 2025-11-28 15:34:01 +01:00
release-plz.toml chore: add CD 2025-11-28 14:40:05 +01:00
rust-toolchain.toml update rust version & nextest installation 2026-03-01 19:27:24 +01:00

event_bus.rs

Crate Version: event_bus_rs

A runtime-agnostic, async, and thread-safe event bus for Rust. Designed to be efficient, simple, and easy to use, allowing you to publish and subscribe to messages across threads and async tasks.


Features

  • Runtime-agnostic: works with any async runtime (Tokio, async-std, smol, etc.)
  • Thread-safe: multiple publishers and subscribers can safely coexist
  • Async & Stream-based: subscribers implement futures::Stream
  • Automatic cleanup: topics are removed when the last subscriber drops
  • Minimal & simple API: just EventBus::subscribe and EventBus::publish

Topic capacity

The EventBus is build on top of bounded channels, which means that each time a topic is created, we need to specify a capacity.

The default one is set to an arbitrary value which is available and documented in the docs.

To know more about how the bounded channels work, check async_broadcast


Installation

Add to your Cargo.toml:

[dependencies]
event_bus_rs = "0.1.0"
futures = "0.3"

Usage Example

use event_bus_rs::EventBus;
use futures::StreamExt;

#[tokio::main]
async fn main() {
    let bus = EventBus::new_with_topic_capacity(50);

    // Subscribe to a topic
    let mut sub = bus.subscribe("my_topic");

    // Spawn a subscriber task
    tokio::spawn(async move {
        while let Some(msg) = sub.next().await {
            println!("Received: {}", String::from_utf8_lossy(&msg));
        }
    });

    // Publish a message
    bus.publish("my_topic", b"Hello, EventBus!").unwrap();
}

Notes:

  • Messages are published as &[u8]; encoding/decoding is the user's responsibility.
  • Multiple subscribers to the same topic each get a copy of every message.
  • When all subscribers of a topic are dropped, the topic is automatically cleaned up.

API Overview

  • EventBus::new() -> EventBus create a new bus
  • EventBus::new_with_topic_capacity() -> EventBus - create a new but with a configure topic capacity
  • EventBus::subscribe(&self, topic: &str) -> Subscription subscribe to a topic
  • EventBus::publish(&self, topic: &str, data: &[u8]) -> Result<(), PublishError> publish a message
  • Subscription implements futures::Stream<Item = Arc<[u8]>>

License

MIT OR Apache-2.0