EventBus
Defined in: packages/cqrs/src/event.bus.ts:40
Starts every handler of an event, each through its own pipeline, and returns without
awaiting them. createCqrs() builds it; it satisfies IDomainEventPublisher of
@cqrs-ddd/core, so CommandBaseHandler takes it as its event publisher.
Example
Section titled “Example”cqrs.eventBus.publish(new UserCreatedEvent(user.id));Type Parameters
Section titled “Type Parameters”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new EventBus<
E>(handlers,unhandled,options?):EventBus<E>
Defined in: packages/cqrs/src/event.bus.ts:49
Parameters
Section titled “Parameters”handlers
Section titled “handlers”ReadonlyMap<AnyClass, readonly EventSubscriber[]>
Maps each event class to its handlers. The bus reads it at every call, so it can be filled after the bus is created, as handlers that inject the bus require.
unhandled
Section titled “unhandled”Receives the failures of handlers.
options?
Section titled “options?”EventBusOptions = {}
Returns
Section titled “Returns”EventBus<E>
Methods
Section titled “Methods”drain()
Section titled “drain()”drain():
Promise<void>
Defined in: packages/cqrs/src/event.bus.ts:105
Resolves once every handler started so far has settled, including handlers those
handlers start meanwhile. app.close() calls it, so a shutdown or a test ends
after the work it caused.
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example”eventBus.publish(new UserCreatedEvent(user.id));await eventBus.drain();publish()
Section titled “publish()”publish<
T>(event):void
Defined in: packages/cqrs/src/event.bus.ts:69
Starts the handlers of the event’s class, or of its nearest parent class that has
any; their synchronous part runs before publish returns. An event without handlers
is dropped. A failure goes to the UnhandledExceptionBus and the logger, never to
the caller.
Type Parameters
Section titled “Type Parameters”T extends IEvent
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”void
Example
Section titled “Example”eventBus.publish(new UserCreatedEvent(user.id));publishAll()
Section titled “publishAll()”publishAll<
T>(events):void
Defined in: packages/cqrs/src/event.bus.ts:90
Publishes each event in order, as publish does.
Type Parameters
Section titled “Type Parameters”T extends IEvent
Parameters
Section titled “Parameters”events
Section titled “events”readonly T[]
Returns
Section titled “Returns”void
Example
Section titled “Example”eventBus.publishAll(order.getUncommittedEvents());