Skip to main content

Class: EventBusService

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

Hierarchy

  • TransactionBaseServiceCopy to Clipboard

    EventBusServiceCopy to Clipboard

Implements

  • IEventBusServiceCopy to Clipboard

Constructors

constructor

new EventBusService(__namedParametersCopy to Clipboard, configCopy to Clipboard, isSingleton?Copy to Clipboard)

Parameters

NameTypeDefault value
__namedParametersCopy to ClipboardInjectedDependenciesCopy to ClipboardundefinedCopy to Clipboard
configCopy to ClipboardanyCopy to ClipboardundefinedCopy to Clipboard
isSingletonCopy to ClipboardbooleanCopy to ClipboardtrueCopy to Clipboard

Overrides

TransactionBaseService.constructor

Defined in

medusa/src/services/event-bus.ts:32

Properties

__configModule__

ProtectedCopy to Clipboard OptionalCopy to Clipboard ReadonlyCopy to Clipboard __configModule__: RecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>

Inherited from

TransactionBaseService.__configModule__

Defined in

medusa/src/interfaces/transaction-base-service.ts:14


__container__

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard __container__: anyCopy to Clipboard

Inherited from

TransactionBaseService.__container__

Defined in

medusa/src/interfaces/transaction-base-service.ts:13


__moduleDeclaration__

ProtectedCopy to Clipboard OptionalCopy to Clipboard ReadonlyCopy to Clipboard __moduleDeclaration__: RecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>

Inherited from

TransactionBaseService.__moduleDeclaration__

Defined in

medusa/src/interfaces/transaction-base-service.ts:15


config_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard config_: ConfigModuleCopy to Clipboard

Defined in

medusa/src/services/event-bus.ts:24


enqueue_

ProtectedCopy to Clipboard enqueue_: PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

medusa/src/services/event-bus.ts:30


eventBusModuleService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard eventBusModuleService_: IEventBusModuleServiceCopy to Clipboard

Defined in

medusa/src/services/event-bus.ts:27


manager_

ProtectedCopy to Clipboard manager_: EntityManagerCopy to Clipboard

Inherited from

TransactionBaseService.manager_

Defined in

medusa/src/interfaces/transaction-base-service.ts:5


shouldEnqueuerRun

ProtectedCopy to Clipboard shouldEnqueuerRun: booleanCopy to Clipboard

Defined in

medusa/src/services/event-bus.ts:29


stagedJobService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard stagedJobService_: StagedJobServiceCopy to Clipboard

Defined in

medusa/src/services/event-bus.ts:25


transactionManager_

ProtectedCopy to Clipboard transactionManager_: undefinedCopy to Clipboard | EntityManagerCopy to Clipboard

Inherited from

TransactionBaseService.transactionManager_

Defined in

medusa/src/interfaces/transaction-base-service.ts:6

Accessors

activeManager_

ProtectedCopy to Clipboard getCopy to Clipboard activeManager_(): EntityManagerCopy to Clipboard

Returns

EntityManagerCopy to Clipboard

Inherited from

TransactionBaseService.activeManager_

Defined in

medusa/src/interfaces/transaction-base-service.ts:8

Methods

atomicPhase_

ProtectedCopy to Clipboard atomicPhase_<TResultCopy to Clipboard, TErrorCopy to Clipboard>(workCopy to Clipboard, isolationOrErrorHandler?Copy to Clipboard, maybeErrorHandlerOrDontFail?Copy to Clipboard): PromiseCopy to Clipboard<TResultCopy to Clipboard>

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

Name
TResultCopy to Clipboard
TErrorCopy to Clipboard

Parameters

NameTypeDescription
workCopy to Clipboard(transactionManagerCopy to Clipboard: EntityManagerCopy to Clipboard) => PromiseCopy to Clipboard<TResultCopy to Clipboard>the transactional work to be done
isolationOrErrorHandler?Copy to ClipboardIsolationLevelCopy to Clipboard | (errorCopy to Clipboard: TErrorCopy to Clipboard) => PromiseCopy to Clipboard<voidCopy to Clipboard | TResultCopy to Clipboard>the isolation level to be used for the work.
maybeErrorHandlerOrDontFail?Copy to Clipboard(errorCopy to Clipboard: TErrorCopy to Clipboard) => PromiseCopy to Clipboard<voidCopy to Clipboard | TResultCopy to Clipboard>Potential error handler

Returns

PromiseCopy to Clipboard<TResultCopy to Clipboard>

the result of the transactional work

Inherited from

TransactionBaseService.atomicPhase_

Defined in

medusa/src/interfaces/transaction-base-service.ts:56


emit

emit<TCopy to Clipboard>(dataCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard | StagedJobCopy to Clipboard[]>

Calls all subscribers when an event occurs.

Type parameters

Name
TCopy to Clipboard

Parameters

NameTypeDescription
dataCopy to ClipboardEmitDataCopy to Clipboard<TCopy to Clipboard>[]The data to use to process the events

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard | StagedJobCopy to Clipboard[]>

the jobs from our queue

Implementation of

EventBusTypes.IEventBusService.emit

Defined in

medusa/src/services/event-bus.ts:112

emit<TCopy to Clipboard>(eventNameCopy to Clipboard, dataCopy to Clipboard, options?Copy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard | StagedJobCopy to Clipboard>

Calls all subscribers when an event occurs.

Type parameters

Name
TCopy to Clipboard

Parameters

NameTypeDescription
eventNameCopy to ClipboardstringCopy to Clipboardthe name of the event to be process.
dataCopy to ClipboardTCopy to Clipboardthe data to send to the subscriber.
options?Copy to ClipboardRecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>options to add the job with

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard | StagedJobCopy to Clipboard>

the job from our queue

Implementation of

EventBusTypes.IEventBusService.emit

Defined in

medusa/src/services/event-bus.ts:121


enqueuer_

enqueuer_(): PromiseCopy to Clipboard<voidCopy to Clipboard>

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

medusa/src/services/event-bus.ts:185


shouldRetryTransaction_

ProtectedCopy to Clipboard shouldRetryTransaction_(errCopy to Clipboard): booleanCopy to Clipboard

Parameters

NameType
errCopy to ClipboardRecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard> | { codeCopy to Clipboard: stringCopy to Clipboard }

Returns

booleanCopy to Clipboard

Inherited from

TransactionBaseService.shouldRetryTransaction_

Defined in

medusa/src/interfaces/transaction-base-service.ts:37


startEnqueuer

startEnqueuer(): voidCopy to Clipboard

Returns

voidCopy to Clipboard

Defined in

medusa/src/services/event-bus.ts:175


stopEnqueuer

stopEnqueuer(): PromiseCopy to Clipboard<voidCopy to Clipboard>

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

medusa/src/services/event-bus.ts:180


subscribe

subscribe(eventCopy to Clipboard, subscriberCopy to Clipboard, context?Copy to Clipboard): EventBusServiceCopy to Clipboard

Adds a function to a list of event subscribers.

Parameters

NameTypeDescription
eventCopy to ClipboardstringCopy to Clipboard | symbolCopy to Clipboardthe event that the subscriber will listen for.
subscriberCopy to ClipboardSubscriberCopy to Clipboard<unknownCopy to Clipboard>the function to be called when a certain event happens. Subscribers must return a Promise.
context?Copy to ClipboardSubscriberContextCopy to Clipboardsubscriber context

Returns

EventBusServiceCopy to Clipboard

this

Implementation of

EventBusTypes.IEventBusService.subscribe

Defined in

medusa/src/services/event-bus.ts:78


unsubscribe

unsubscribe(eventCopy to Clipboard, subscriberCopy to Clipboard, contextCopy to Clipboard): EventBusServiceCopy to Clipboard

Removes function from the list of event subscribers.

Parameters

NameTypeDescription
eventCopy to ClipboardstringCopy to Clipboard | symbolCopy to Clipboardthe event of the subcriber.
subscriberCopy to ClipboardSubscriberCopy to Clipboard<unknownCopy to Clipboard>the function to be removed
contextCopy to ClipboardSubscriberContextCopy to Clipboardsubscriber context

Returns

EventBusServiceCopy to Clipboard

this

Implementation of

EventBusTypes.IEventBusService.unsubscribe

Defined in

medusa/src/services/event-bus.ts:98


withTransaction

withTransaction(transactionManager?Copy to Clipboard): EventBusServiceCopy to Clipboard

Parameters

NameType
transactionManager?Copy to ClipboardEntityManagerCopy to Clipboard

Returns

EventBusServiceCopy to Clipboard

Implementation of

EventBusTypes.IEventBusService.withTransaction

Overrides

TransactionBaseService.withTransaction

Defined in

medusa/src/services/event-bus.ts:49

Was this page helpful?