Skip to content

@yantrix/automata v0.6.0 • Docs


Yantrix API / @yantrix/automata / BasicEventBus

Class: BasicEventBus ​

Basic event bus class that is used in Yantrix automatas.

Extends ​

  • AbstractAutomataEventBus<number, Record<number, any>, typeof AbstractBaseClass, this> & AbstractBaseClass<this>

Implements ​

Methods ​

_processEvents() ​

ts
_processEvents(): Promise<TAutomataEventStack<number, Record<number, any>>>

Processes Events in the Event Stack and handles them using subscribed callbacks.

This method iterates over the Event Stack, invoking the corresponding callbacks for each valid Event, and processes a batch of Events limited by STACK_PROCESSING_BATCH_SIZE. When tasks repeatedly return more copies of their own Event ID than the batch consumed, limit their cumulative growth relative to the queue size after the first expanding batch. An isolated fan-out is allowed.

Returns ​

Promise<TAutomataEventStack<number, Record<number, any>>>

new Events acquired from processing the queue.

Throws ​

If the recursion limit, calculated as a ratio of the stack length, is exceeded for any Event.

Inherited from ​

createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass)._processEvents


clearEventStack() ​

ts
clearEventStack(): this

Clear the event stack.

Returns ​

this

Implementation of ​

IAutomataEventBus.clearEventStack

Inherited from ​

createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).clearEventStack


dispatch() ​

ts
dispatch(...events): this

Dispatch one or more events.

Parameters ​

• ...events: TAutomataEventStack<number, Record<number, any>>

The events to dispatch

Returns ​

this

This event bus instance

Implementation of ​

IAutomataEventBus.dispatch

Inherited from ​

createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).dispatch


getEventStack() ​

ts
getEventStack(): TAutomataEventStack<number, Record<number, any>>

Get the current event stack.

Returns ​

TAutomataEventStack<number, Record<number, any>>

The current event stack.

Implementation of ​

IAutomataEventBus.getEventStack

Inherited from ​

createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).getEventStack


isRunning() ​

ts
isRunning(): boolean

Check if the event bus is running.

Returns ​

boolean

True if the event bus is running, false otherwise.

Implementation of ​

IAutomataEventBus.isRunning

Inherited from ​

createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).isRunning


pause() ​

ts
pause(): this

Pause the event bus.

Returns ​

this

This event bus instance.

Implementation of ​

IAutomataEventBus.pause

Inherited from ​

createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).pause


resume() ​

ts
resume(): this

Resume the event bus.

Returns ​

this

This event bus instance.

Implementation of ​

IAutomataEventBus.resume

Inherited from ​

createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).resume


subscribe() ​

ts
subscribe(event, callback): this

Subscribe to an event.

Parameters ​

• event: number

The event to subscribe to

• callback: TEventBusHandler<number, Record<number, any>>

The callback to call when the event is received

Returns ​

this

This event bus instance

Implementation of ​

IAutomataEventBus.subscribe

Inherited from ​

createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).subscribe


unsubscribe() ​

ts
unsubscribe(event, callback): this

Unsubscribe from an event.

Parameters ​

• event: number

The event to unsubscribe from.

• callback: null | TEventBusHandler<number, Record<number, any>>

The callback function to unsubscribe.

Returns ​

this

This event bus instance.

Implementation of ​

IAutomataEventBus.unsubscribe

Inherited from ​

createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).unsubscribe


whenIdle() ​

ts
whenIdle(): Promise<void>

Resolves after the Event Stack and all asynchronous follow-up Events have been fully processed.

Returns ​

Promise<void>

Implementation of ​

IAutomataEventBus.whenIdle

Inherited from ​

createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).whenIdle