Instanciate the bus with an underlying EventStorage.
where your events will be stored.
where your events will be stored.
Listen to error. You really should write at least one error handler because EventBus is an instance of
EventEmitter, if it emits an error while no listener is attached, it throws.
error handler
The handler is called for every published event.
If the handler throws or returns a rejecting promise, an error will be emitted.
event handler
When you publish an event, it is first stored in the EventStorage then it is emitted to every subscribers.
the event to publish
Generated using TypeDoc
The
EventEmitterthat stores and publishes events.const bus = new EventBus(new InMemoryEventStorage()); bus.onError((err) => { console.error(err); }); bus.onEvent((event) => { console.log(`Something happened: ${event}`); }); bus.publish({ aggregate: 'cat', id: 'felix', sequence: 0, type: 'fed' });