FSM
Defined in: src/fsm/FSM.ts:47
Finite-State-Machine DSL built on top of the OO Actor class. Each
state has a name, an onReceive handler that returns the next transition,
and optional enter/exit callbacks. Internally the FSM stores the
current state name, so it’s friendlier than raw become() for
protocols with a small, named state set.
Usage: class Door extends FSM<‘closed’|‘open’, { openedAt?: number }, DoorCmd> { constructor() { super(‘closed’, { }); this.when(‘closed’, (d, m) => m === ‘open’ ? this.goto(‘open’, { openedAt: Date.now() }) : this.stay(d)); this.when(‘open’, (d, m) => m === ‘close’ ? this.goto(‘closed’, { }) : this.stay(d)); } }
Extends
Section titled “Extends”Actor<Msg>
Type Parameters
Section titled “Type Parameters”SName extends string
SData
Msg
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new FSM<
SName,SData,Msg>(initialState,initialData):FSM<SName,SData,Msg>
Defined in: src/fsm/FSM.ts:55
Parameters
Section titled “Parameters”initialState
Section titled “initialState”SName
initialData
Section titled “initialData”SData
Returns
Section titled “Returns”FSM<SName, SData, Msg>
Overrides
Section titled “Overrides”Methods
Section titled “Methods”onReceive()
Section titled “onReceive()”onReceive(
msg):Promise<void>
Defined in: src/fsm/FSM.ts:93
Main message handler. Receives each envelope dequeued from the mailbox. A thrown error (sync or async) is caught by the supervisor.
Parameters
Section titled “Parameters”Msg
Returns
Section titled “Returns”Promise<void>
Overrides
Section titled “Overrides”postRestart()
Section titled “postRestart()”postRestart(
_reason):void|Promise<void>
Defined in: src/Actor.ts:55
Called on the fresh instance after a restart. Default: call preStart().
Parameters
Section titled “Parameters”_reason
Section titled “_reason”Error
Returns
Section titled “Returns”void | Promise<void>
Inherited from
Section titled “Inherited from”postStop()
Section titled “postStop()”postStop():
void|Promise<void>
Defined in: src/Actor.ts:44
Called after the actor has been terminated. Children are already stopped.
Returns
Section titled “Returns”void | Promise<void>
Inherited from
Section titled “Inherited from”preRestart()
Section titled “preRestart()”preRestart(
_reason,_message?):void|Promise<void>
Defined in: src/Actor.ts:50
Called before a restart, on the instance about to be thrown away. The default stops children and then calls postStop().
Parameters
Section titled “Parameters”_reason
Section titled “_reason”Error
_message?
Section titled “_message?”Msg
Returns
Section titled “Returns”void | Promise<void>
Inherited from
Section titled “Inherited from”preStart()
Section titled “preStart()”preStart():
void|Promise<void>
Defined in: src/Actor.ts:41
Called after construction and before the first message is processed.
Returns
Section titled “Returns”void | Promise<void>
Inherited from
Section titled “Inherited from”supervisorStrategy()
Section titled “supervisorStrategy()”supervisorStrategy():
SupervisorStrategy
Defined in: src/Actor.ts:63
Supervisor strategy for this actor’s children. Defaults to restart, up to 10 times per minute, then stop.