Skip to main content
Skip to main content

EventBusService

internal.internal.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
eventBusModuleService_IEventBusModuleServiceRequired
logger_LoggerRequired
manager_EntityManagerRequired
shouldEnqueuerRunbooleanRequired
stagedJobService_StagedJobServiceRequired
transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Protected get activeManager_(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Inherited from

TransactionBaseService.activeManager_

Methods

atomicPhase_

Protected atomicPhase_<TResult, 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.

TResultobjectRequired
TErrorobjectRequired

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

Promise<TResult>

PromisePromise<TResult>Required
the result of the transactional work

Inherited from

TransactionBaseService.atomicPhase_


emit

emit<T>(data): Promise<void | StagedJob[]>

Calls all subscribers when an event occurs.

TobjectRequired

Parameters

dataEmitData<T>[]Required
The data to use to process the events

Returns

Promise<void | StagedJob[]>

PromisePromise<void | StagedJob[]>Required
the jobs from our queue

Implementation of

IEventBusService.emit

emit<T>(eventName, data, options?): Promise<void | StagedJob>

Calls all subscribers when an event occurs.

TobjectRequired

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

Promise<void | StagedJob>

PromisePromise<void | StagedJob>Required
the job from our queue

Implementation of

EventBusTypes.IEventBusService.emit


enqueuer_

enqueuer_(): Promise<void>

Returns

Promise<void>

PromisePromise<void>Required

listJobs

Protected listJobs(listConfig): Promise<never[] | StagedJob[]>

Parameters

listConfigFindConfig<StagedJob>Required

Returns

Promise<never[] | StagedJob[]>

PromisePromise<never[] | StagedJob[]>Required

shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

errRecord<string, unknown> | { code: string }Required

Returns

boolean

booleanboolean

Inherited from

TransactionBaseService.shouldRetryTransaction_


startEnqueuer

startEnqueuer(): void

Returns

void

voidvoid

stopEnqueuer

stopEnqueuer(): Promise<void>

Returns

Promise<void>

PromisePromise<void>Required

subscribe

subscribe(event, subscriber, context?): EventBusService

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

EventBusService

defaultEventBusServiceRequired
this

Implementation of

IEventBusService.subscribe


unsubscribe

unsubscribe(event, subscriber, context): EventBusService

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

EventBusService

defaultEventBusServiceRequired
this

Implementation of

IEventBusService.unsubscribe


withTransaction

withTransaction(transactionManager?): EventBusService

Parameters

transactionManagerEntityManager

Returns

EventBusService

defaultEventBusServiceRequired

Implementation of

IEventBusService.withTransaction

Overrides

TransactionBaseService.withTransaction

Was this section helpful?