Skip to content

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.

cqrs.eventBus.publish(new UserCreatedEvent(user.id));

E extends IEvent = IEvent

new EventBus<E>(handlers, unhandled, options?): EventBus<E>

Defined in: packages/cqrs/src/event.bus.ts:49

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.

UnhandledExceptionBus

Receives the failures of handlers.

EventBusOptions = {}

EventBus<E>

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.

Promise<void>

eventBus.publish(new UserCreatedEvent(user.id));
await eventBus.drain();

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.

T extends IEvent

T

void

eventBus.publish(new UserCreatedEvent(user.id));

publishAll<T>(events): void

Defined in: packages/cqrs/src/event.bus.ts:90

Publishes each event in order, as publish does.

T extends IEvent

readonly T[]

void

eventBus.publishAll(order.getUncommittedEvents());