EventBusService
Can keep track of multiple subscribers to different events and run the subscribers when events happen. Events will run asynchronously.
constructor
Parameters
__namedParametersInjectedDependenciesRequiredconfiganyRequiredisSingletonbooleanRequiredDefault: true
Properties
__container__anyRequiredenqueue_Promise<void>Requiredmanager_EntityManagerRequiredshouldEnqueuerRunbooleanRequiredtransactionManager_undefined | EntityManagerRequired__configModule__Record<string, unknown>__moduleDeclaration__Record<string, unknown>Accessors
activeManager_
Returns
EntityManagerEntityManagerRequiredeventBusModuleService_
Returns
IEventBusModuleServiceobjectRequiredMethods
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
TResultobjectRequiredTErrorobjectRequiredParameters
work(transactionManager: EntityManager) => Promise<TResult>Requiredthe 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>Requiredthe result of the transactional work
emit
**emit**<TypeParameter T>(data): Promise<void \| [StagedJob](/references/entities/classes/StagedJob)[]>
Calls all subscribers when an event occurs.
Type Parameters
TobjectRequiredParameters
The data to use to process the events
Returns
the jobs from our queue
**emit**<TypeParameter T>(eventName, data, options?): Promise<void \| [StagedJob](/references/entities/classes/StagedJob)>
Calls all subscribers when an event occurs.
Type Parameters
TobjectRequiredParameters
eventNamestringRequiredthe name of the event to be process.
dataTRequiredthe data to send to the subscriber.
optionsRecord<string, unknown>options to add the job with
Returns
the job from our queue
enqueuer_
Returns
PromisePromise<void>RequiredlistJobs
Parameters
Returns
shouldRetryTransaction_
Parameters
errRecord<string, unknown> | objectRequiredReturns
booleanbooleanRequiredstartEnqueuer
Returns
voidvoidRequiredstopEnqueuer
Returns
PromisePromise<void>Requiredsubscribe
Adds a function to a list of event subscribers.
Parameters
eventstring | symbolRequiredthe event that the subscriber will listen for.
the function to be called when a certain event
happens. Subscribers must return a Promise.
contextSubscriberContextsubscriber context
Returns
thisthisRequiredthis
unsubscribe
Removes function from the list of event subscribers.
Parameters
eventstring | symbolRequiredthe event of the subcriber.
the function to be removed
subscriber context
Returns
thisthisRequiredthis
withTransaction
Parameters
transactionManagerEntityManagerReturns
thisthisRequiredWas this section helpful?