/ fm / liveswitch / StateMachine
Class: StateMachine<T>
fm.liveswitch.StateMachine
A simple state machine.
Type parameters
| Name |
|---|
T |
Hierarchy
StateMachine
Table of contents
Constructors
Methods
- addTransition
- canTransition
- fmliveswitchStateMachineInit
- getLastStateMillis
- getLastStateTicks
- getPromise
- getState
- getStateValue
- getSystemTimestamp
- getTypeString
- isReachable
- stateToValue
- transition
- valueToState
Constructors
constructor
+ new StateMachine<T>(initialState: T): StateMachine<T>
Initializes a new instance of the [[fm.liveswitch.stateMachine]] class.
Type parameters:
| Name |
|---|
T |
Parameters:
| Name | Type | Description |
|---|---|---|
initialState |
T | The initial state. |
Returns: StateMachine<T>
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:34
Methods
addTransition
▸ addTransition(fromState: T, toState: T): void
Adds an allowed transition.
Parameters:
| Name | Type | Description |
|---|---|---|
fromState |
T | The "from" state. |
toState |
T | The "to" state. |
Returns: void
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:85
canTransition
▸ canTransition(toState: T): boolean
Determines whether a transition to the specified state is allowed.
Parameters:
| Name | Type | Description |
|---|---|---|
toState |
T | The "to" state. |
Returns: boolean
true if a transition to the specified state is allowed; otherwise, false.
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:118
fmliveswitchStateMachineInit
▸ PrivatefmliveswitchStateMachineInit(): void
Returns: void
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:29
getLastStateMillis
▸ getLastStateMillis(): number
Gets the length of time spent in the last state, in milliseconds.
Returns: number
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:183
getLastStateTicks
▸ getLastStateTicks(): number
Gets the length of time spent in the last state, in ticks.
Returns: number
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:200
getPromise
▸ getPromise<R>(state: T, returnValue: R): Promise<R>
Gets a promise, which may be resolved or rejected depending on the current state of this machine.
Type parameters:
| Name | Type |
|---|---|
R |
Object |
Parameters:
| Name | Type | Description |
|---|---|---|
state |
T | State, in which promise must be resolved. |
returnValue |
R | Return type of this promise. |
Returns: Promise<R>
Promise, which may be resolved or rejected depending on the current state of this machine
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:215
getState
▸ getState(): T
Gets the state.
Returns: T
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:238
getStateValue
▸ ProtectedgetStateValue(): number
Gets the state value.
Returns: number
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:250
getSystemTimestamp
▸ getSystemTimestamp(): number
Gets the system timestamp of the last state transition.
Returns: number
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:263
getTypeString
▸ getTypeString(): string
Returns: string
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:9
isReachable
▸ isReachable(state: T): boolean
Determines whether a transition to a specified state is possible (even via intermediate hops).
Parameters:
| Name | Type | Description |
|---|---|---|
state |
T | The "to" state. |
Returns: boolean
true if a transition to the specified state is possible; otherwise, false.
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:278
stateToValue
▸ Protected AbstractstateToValue(state: T): number
Converts a state to an integer value.
Parameters:
| Name | Type | Description |
|---|---|---|
state |
T | The state. |
Returns: number
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:324
transition
▸ transition(toState: T): boolean
Transitions to the specified state.
Parameters:
| Name | Type | Description |
|---|---|---|
toState |
T | The "to" state. |
Returns: boolean
true if a transition to the specified state is allowed; otherwise, false.
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:333
valueToState
▸ Protected AbstractvalueToState(value: number): T
Converts an integer value to a state.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | The integer value. |
Returns: T
Defined in: Generated/TypeScript/fm.liveswitch/StateMachine.ts:373