Lightweight async message bus with fire-and-forget events and typed RPC calls. Zero dependencies. Fully TypeScript.
send()— broadcast to all listeners (non-blocking)call()— request/response to exactly one listener (awaits result)on()— register listeneronce()— auto-unregister after first calloff()— remove listener (topic auto-cleanup)- Random routing when multiple RPC listeners exist
- Type-safe payloads and return types per topic
- Support CJS and ESM
import { Bus } from "@papack/bus";
type Topic = "log" | "calc";
const bus = new Bus<Topic>();
bus.on("log", async (msg) => console.log(msg));
bus.on("calc", async (n) => n * 2);
bus.send("log", "Hello");
const result = await bus.call<number, number>("calc", 21);
console.log(result); // 42- an implementation of the BusPort that work in multiprocess Node
- use like
const bus = new ClusterBus()
- an implementation of the BusPort that work with Redis
- inject Redis client to keep 0 Dependencys
- use like
const bus = new RedisBus({client:redisClient})
Idea: a Gossip Port for peer-to-peer message propagation using a gossip protocol.