Skip to main content
Skip to main content

EventBusService

Can keep track of multiple subscribers to different events and run the subscribers when events happen. Events will run asynchronously.

constructor

Parameters

__namedParametersInjectedDependenciesRequired
configConfigModuleRequired
isSingletonbooleanRequired

Default: true


Properties

manager_EntityManagerRequired
transactionManager_undefined | EntityManagerRequired
__container__anyRequired
config_ConfigModuleRequired
stagedJobService_StagedJobServiceRequired
logger_LoggerRequired
shouldEnqueuerRunbooleanRequired
enqueue_Promise<void>Required
__configModule__Record<string, unknown>
__moduleDeclaration__Record<string, unknown>

Accessors

activeManager_

Returns

EntityManagerEntityManagerRequired

eventBusModuleService_

Returns

IEventBusModuleServiceobjectRequired

Methods

shouldRetryTransaction_

Parameters

errRecord<string, unknown> | objectRequired

Returns

booleanbooleanRequired

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

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

PromisePromise<TResult>Required
the result of the transactional work

withTransaction

Parameters

transactionManagerEntityManager

Returns

thisthisRequired

subscribe

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

thisthisRequired
this

unsubscribe

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

thisthisRequired
this

emit

**emit**<TypeParameter T>(data): Promise&#60;void \| [StagedJob](../../entities/classes/entities.StagedJob.mdx)[]&#62;

Calls all subscribers when an event occurs.

Type Parameters

TobjectRequired

Parameters

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

Returns

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

**emit**<TypeParameter T>(data): Promise&#60;void \| [StagedJob](../../entities/classes/entities.StagedJob.mdx)[]&#62;

Type Parameters

TobjectRequired

Parameters

dataMessage<T>[]Required

Returns

PromisePromise<void | StagedJob[]>Required

**emit**<TypeParameter T>(eventName, data, options?): Promise&#60;void \| [StagedJob](../../entities/classes/entities.StagedJob.mdx)&#62;

Calls all subscribers when an event occurs.

Type Parameters

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

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

startEnqueuer

Returns

voidvoidRequired

stopEnqueuer

Returns

PromisePromise<void>Required

enqueuer_

Returns

PromisePromise<void>Required

listJobs

Parameters

listConfigFindConfig<StagedJob>Required

Returns

PromisePromise<never[] | StagedJob[]>Required
Was this section helpful?