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.

Implements

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_

Inherited from

TransactionBaseService.activeManager_


eventBusModuleService_

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.

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/js-client/internal/classes/internal.internal.StagedJob)[]&#62;

Calls all subscribers when an event occurs.

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/js-client/internal/classes/internal.internal.StagedJob)&#62;

Calls all subscribers when an event occurs.

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> | { code: string }Required
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
defaultEventBusServiceRequired
this

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
defaultEventBusServiceRequired
this

withTransaction

Parameters
transactionManagerEntityManager
Returns
defaultEventBusServiceRequired
Was this section helpful?