Skip to main content
Skip to main content

EventBusService

Can keep track of multiple subscribers to different events and run the subscribers when events happen. Events will run asynchronously.

constructor

Parameters

__namedParametersInjectedDependenciesRequired
configanyRequired
isSingletonbooleanRequired

Default: true


Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
config_ConfigModuleRequired
enqueue_Promise<void>Required
logger_LoggerRequired
manager_EntityManagerRequired
shouldEnqueuerRunbooleanRequired
stagedJobService_StagedJobServiceRequired
transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Returns

EntityManagerEntityManagerRequired

eventBusModuleService_

Returns

IEventBusModuleServiceIEventBusModuleServiceRequired

Methods

atomicPhase_

Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.

Type Parameters

TResultobjectRequired
TErrorobjectRequired

Parameters

work(transactionManager: EntityManager) => Promise<TResult>Required
the transactional work to be done
isolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>
the isolation level to be used for the work.
maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>
Potential error handler

Returns

PromisePromise<TResult>Required
the result of the transactional work

emit

**emit**<TypeParameter T>(data): Promise&#60;void \| [StagedJob](/references/entities/classes/StagedJob)[]&#62;

Calls all subscribers when an event occurs.

Type Parameters

TobjectRequired

Parameters

dataEmitData<T>[]Required
The data to use to process the events

Returns

PromisePromise<void | StagedJob[]>Required
the jobs from our queue

**emit**<TypeParameter T>(eventName, data, options?): Promise&#60;void \| [StagedJob](/references/entities/classes/StagedJob)&#62;

Calls all subscribers when an event occurs.

Type Parameters

TobjectRequired

Parameters

eventNamestringRequired
the name of the event to be process.
dataTRequired
the data to send to the subscriber.
optionsRecord<string, unknown>
options to add the job with

Returns

PromisePromise<void | StagedJob>Required
the job from our queue

enqueuer_

Returns

PromisePromise<void>Required

listJobs

Parameters

listConfigFindConfig<StagedJob>Required

Returns

PromisePromise<never[] | StagedJob[]>Required

shouldRetryTransaction_

Parameters

errRecord<string, unknown> | objectRequired

Returns

booleanboolean

startEnqueuer

Returns

voidvoid

stopEnqueuer

Returns

PromisePromise<void>Required

subscribe

Adds a function to a list of event subscribers.

Parameters

eventstring | symbolRequired
the event that the subscriber will listen for.
subscriberSubscriber<unknown>Required
the function to be called when a certain event happens. Subscribers must return a Promise.
subscriber context

Returns

EventBusServiceobjectRequired
Can keep track of multiple subscribers to different events and run the subscribers when events happen. Events will run asynchronously.

unsubscribe

Removes function from the list of event subscribers.

Parameters

eventstring | symbolRequired
the event of the subcriber.
subscriberSubscriber<unknown>Required
the function to be removed
contextSubscriberContextRequired
subscriber context

Returns

EventBusServiceobjectRequired
Can keep track of multiple subscribers to different events and run the subscribers when events happen. Events will run asynchronously.

withTransaction

Parameters

transactionManagerEntityManager

Returns

EventBusServiceobjectRequired
Can keep track of multiple subscribers to different events and run the subscribers when events happen. Events will run asynchronously.
Was this section helpful?