EventBusService
Can keep track of multiple subscribers to different events and run the subscribers when events happen. Events will run asynchronously.
Implements
Constructors
constructor
**new EventBusService**(«destructured», config, isSingleton?)
Parameters
config
anyRequiredisSingleton
booleanRequiredDefault: true
Properties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>enqueue_
Promise<void>Requiredmanager_
EntityManagerRequiredshouldEnqueuerRun
booleanRequiredtransactionManager_
undefined | EntityManagerRequiredAccessors
activeManager_
Protected get**activeManager_**(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredeventBusModuleService_
Protected get**eventBusModuleService_**(): [IEventBusModuleService](/references/services/interfaces/IEventBusModuleService)
Returns
Methods
atomicPhase_
Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise<TResult>
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.
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise<TResult>
Promise
Promise<TResult>Requiredemit
**emit**<TypeParameter T>(data): Promise<void \| [StagedJob](/references/services/classes/StagedJob)[]>
Calls all subscribers when an event occurs.
T
objectRequiredParameters
Returns
Promise<void | StagedJob[]>
**emit**<TypeParameter T>(eventName, data, options?): Promise<void \| [StagedJob](/references/services/classes/StagedJob)>
Calls all subscribers when an event occurs.
T
objectRequiredParameters
eventName
stringRequireddata
TRequiredoptions
Record<string, unknown>Returns
Promise<void | StagedJob>
enqueuer_
**enqueuer_**(): Promise<void>
Returns
Promise<void>
Promise
Promise<void>RequiredlistJobs
Protected **listJobs**(listConfig): Promise<never[] \| [StagedJob](/references/services/classes/StagedJob)[]>
Parameters
Returns
Promise<never[] | StagedJob[]>
shouldRetryTransaction_
Protected **shouldRetryTransaction_**(err): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleanstartEnqueuer
**startEnqueuer**(): void
Returns
void
void
voidstopEnqueuer
**stopEnqueuer**(): Promise<void>
Returns
Promise<void>
Promise
Promise<void>Requiredsubscribe
**subscribe**(event, subscriber, context?): [EventBusService](/references/services/classes/EventBusService)
Adds a function to a list of event subscribers.
Parameters
event
string | symbolRequiredcontext
SubscriberContextReturns
unsubscribe
**unsubscribe**(event, subscriber, context): [EventBusService](/references/services/classes/EventBusService)
Removes function from the list of event subscribers.
Parameters
event
string | symbolRequiredReturns
withTransaction
**withTransaction**(transactionManager?): [EventBusService](/references/services/classes/EventBusService)
Parameters
transactionManager
EntityManager