Skip to content

papack/bus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@papack/bus

Lightweight async message bus with fire-and-forget events and typed RPC calls. Zero dependencies. Fully TypeScript.

Features

  • send() — broadcast to all listeners (non-blocking)
  • call() — request/response to exactly one listener (awaits result)
  • on() — register listener
  • once() — auto-unregister after first call
  • off() — remove listener (topic auto-cleanup)
  • Random routing when multiple RPC listeners exist
  • Type-safe payloads and return types per topic
  • Support CJS and ESM

Example

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

Roadmap

v1.1.0 Node Port

  • an implementation of the BusPort that work in multiprocess Node
  • use like const bus = new ClusterBus()

v1.2.0 Redis Port

  • an implementation of the BusPort that work with Redis
  • inject Redis client to keep 0 Dependencys
  • use like const bus = new RedisBus({client:redisClient})

Future

Idea: a Gossip Port for peer-to-peer message propagation using a gossip protocol.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published