@yantrix/automata v0.2.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>, typeofAbstractBaseClass,this> &AbstractBaseClass<this>
Implements
IAutomataEventBus<TAutomataBaseEventType,Record<TAutomataBaseEventType,any>>
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(): thisClear the event stack.
Returns
this
Implementation of
IAutomataEventBus.clearEventStack
Inherited from
createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).clearEventStack
dispatch()
ts
dispatch(...events): thisDispatch one or more events.
Parameters
• ...events: TAutomataEventStack<number, Record<number, any>>
The events to dispatch
Returns
this
This event bus instance
Implementation of
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(): booleanCheck if the event bus is running.
Returns
boolean
True if the event bus is running, false otherwise.
Implementation of
Inherited from
createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).isRunning
pause()
ts
pause(): thisPause the event bus.
Returns
this
This event bus instance.
Implementation of
Inherited from
createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).pause
resume()
ts
resume(): thisResume the event bus.
Returns
this
This event bus instance.
Implementation of
Inherited from
createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).resume
subscribe()
ts
subscribe(event, callback): thisSubscribe 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
Inherited from
createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).subscribe
unsubscribe()
ts
unsubscribe(event, callback): thisUnsubscribe 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
Inherited from
createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass).unsubscribe