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.

Implements

Constructors

constructor

**new EventBusService**(«destructured», config, isSingleton?)

Parameters

__namedParametersInjectedDependenciesRequired
configanyRequired
isSingletonbooleanRequired

Default: true

Properties

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

Accessors

activeManager_

Protected get**activeManager_**(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

eventBusModuleService_

Protected get**eventBusModuleService_**(): [IEventBusModuleService](/references/services/interfaces/IEventBusModuleService)

Returns

IEventBusModuleService

IEventBusModuleServiceIEventBusModuleServiceRequired

Methods

atomicPhase_

Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;

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

emit

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

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

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

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

enqueuer_

**enqueuer_**(): Promise&#60;void&#62;

Returns

Promise<void>

PromisePromise<void>Required

listJobs

Protected **listJobs**(listConfig): Promise&#60;never[] \| [StagedJob](/references/services/classes/StagedJob)[]&#62;

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

startEnqueuer

**startEnqueuer**(): void

Returns

void

voidvoid

stopEnqueuer

**stopEnqueuer**(): Promise&#60;void&#62;

Returns

Promise<void>

PromisePromise<void>Required

subscribe

**subscribe**(event, subscriber, context?): [EventBusService](/references/services/classes/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

unsubscribe

**unsubscribe**(event, subscriber, context): [EventBusService](/references/services/classes/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

withTransaction

**withTransaction**(transactionManager?): [EventBusService](/references/services/classes/EventBusService)

Parameters

transactionManagerEntityManager

Returns

EventBusService

defaultEventBusServiceRequired
Was this section helpful?