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
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>enqueue_
Promise<void>Requiredmanager_
EntityManagerRequiredshouldEnqueuerRun
booleanRequiredtransactionManager_
undefined | EntityManagerRequiredAccessors
activeManager_
Returns
EntityManager
EntityManagerRequiredeventBusModuleService_
Returns
IEventBusModuleService
IEventBusModuleServiceRequiredMethods
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
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
emit
**emit**<TypeParameter T>(data): Promise<void \| [StagedJob](/references/entities/classes/StagedJob)[]>
Calls all subscribers when an event occurs.
Type Parameters
T
objectRequiredParameters
data
EmitData<T>[]RequiredThe 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
enqueuer_
Returns
Promise
Promise<void>RequiredlistJobs
Parameters
Returns
shouldRetryTransaction_
Parameters
err
Record<string, unknown> | objectRequiredReturns
boolean
booleanstartEnqueuer
Returns
void
voidstopEnqueuer
Returns
Promise
Promise<void>Requiredsubscribe
Adds a function to a list of event subscribers.
Parameters
event
string | symbolRequiredthe event that the subscriber will listen for.
subscriber
Subscriber<unknown>Requiredthe function to be called when a certain event
happens. Subscribers must return a Promise.
context
SubscriberContextsubscriber context
Returns
EventBusService
objectRequiredCan 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
event
string | symbolRequiredthe event of the subcriber.
subscriber
Subscriber<unknown>Requiredthe function to be removed
subscriber context
Returns
EventBusService
objectRequiredCan keep track of multiple subscribers to different events and run the
subscribers when events happen. Events will run asynchronously.
withTransaction
Parameters
transactionManager
EntityManagerReturns
EventBusService
objectRequiredCan keep track of multiple subscribers to different events and run the
subscribers when events happen. Events will run asynchronously.
Was this section helpful?