EventBusService
Can keep track of multiple subscribers to different events and run the subscribers when events happen. Events will run asynchronously.
constructor
Parameters
__namedParameters
InjectedDependenciesRequiredconfig
anyRequiredisSingleton
booleanRequiredDefault: true
Properties
manager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequired__container__
anyRequiredshouldEnqueuerRun
booleanRequiredenqueue_
Promise<void>Required__configModule__
Record<string, unknown>__moduleDeclaration__
Record<string, unknown>Accessors
activeManager_
Returns
EntityManager
EntityManagerRequiredeventBusModuleService_
Returns
IEventBusModuleService
objectRequiredMethods
shouldRetryTransaction_
Parameters
err
Record<string, unknown> | objectRequiredReturns
boolean
booleanRequiredatomicPhase_
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
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>Requiredthe transactional work to be done
isolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>the isolation level to be used for the work.
maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Potential error handler
Returns
Promise
Promise<TResult>Requiredthe result of the transactional work
withTransaction
Parameters
transactionManager
EntityManagerReturns
this
thisRequiredsubscribe
Adds a function to a list of event subscribers.
Parameters
event
string | symbolRequiredthe event that the subscriber will listen for.
the function to be called when a certain event
happens. Subscribers must return a Promise.
context
SubscriberContextsubscriber context
Returns
this
thisRequiredthis
unsubscribe
Removes function from the list of event subscribers.
Parameters
event
string | symbolRequiredthe event of the subcriber.
the function to be removed
subscriber context
Returns
this
thisRequiredthis
emit
**emit**<TypeParameter T>(data): Promise<void \| [StagedJob](/references/entities/classes/StagedJob)[]>
Calls all subscribers when an event occurs.
Type Parameters
T
objectRequiredParameters
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
T
objectRequiredParameters
eventName
stringRequiredthe name of the event to be process.
data
TRequiredthe data to send to the subscriber.
options
Record<string, unknown>options to add the job with
Returns
the job from our queue
startEnqueuer
Returns
void
voidRequiredstopEnqueuer
Returns
Promise
Promise<void>Requiredenqueuer_
Returns
Promise
Promise<void>RequiredlistJobs
Parameters
Returns
Was this section helpful?