Skip to content

@yantrix/automata v0.2.0Docs


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. It checks for recursive event emissions and ensures that the recursion limit does not exceed the defined STACK_RECURSION_LIMIT_RATIO relative to the current stack length.

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 n 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