boringnode / bus

A simple and lean service bus implementation for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add events

Julien-R44 opened this issue · comments

On Bentocache, we have these events that are published by the bus: https://bentocache.dev/docs/events#busmessagepublished

bus:message:published and bus:message:received`. These same events are used for monitoring and by the grafana dashboard: https://bentocache.dev/docs/plugin-prometheus#grafana-dashboard

If we want to migrate to rlanz/bus, we also need this


The Bus class would have to accept an emitter as a parameter when instantiated. With an interface like that https://github.com/Julien-R44/bentocache/blob/main/packages/bentocache/src/types/events.ts#L12 so that it's compatible with Node's EventEmitter but also Emiterry

/**
 * Shape of the emitter accepted by BentoCache
 * Should be compatible with node's EventEmitter and Emittery
 */
export interface Emitter {
  on: (event: string, callback: (...values: any[]) => void) => void
  once: (event: string, callback: (...values: any[]) => void) => void
  off: (event: string, callback: (...values: any[]) => void) => void
  emit: (event: string, ...values: any[]) => void
}

the BusManager probably should also accept this emitter

finally not needed