Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/websocket_broadcastchannel/src/state-machine.ts>StateMachine

Host-wide BroadcastChannel for Deno CLI, backed by WebSockets.
Latest
class StateMachine
import { StateMachine } from "https://deno.land/x/websocket_broadcastchannel@0.8.0/src/state-machine.ts";

A state machine.

Constructors

new
StateMachine(
initialState: S,
onBeforeTransition?: OnBeforeTransition<S>,
onDisallowedTransition?: OnDisallowedTransition<S, E>,
allowedTransitions?: TransitionDefinition<S>[],
)

Construct a new StateMachine.

Type Parameters

S

The type of the states.

optional
E extends ErrorResponse = never

The type of the error response from the onDisallowedTransition callback.

Properties

private
_state: S
private
readonly
onBeforeTransition: OnBeforeTransition<S>
private
readonly
onDisallowedTransition: OnDisallowedTransition<S, E>
private
readonly
promiseQueue: PromiseQueue
private
readonly
transitions: Map<S, Map<S, TransitionMeta<S>>>
readonly
state: S

Methods

private
escapePlantUmlString(str?: string): string
private
getAnyTransitionMeta(to: S): TransitionMeta<S> | undefined
private
setTransition(transition: TransitionDefinition<S> & Required<Pick<TransitionDefinition<S>, "fn">>): void
is(...either: S[]): boolean

Checks if current state is any of the arguments.

isFinal(from?: S): boolean
mayTransitionTo(to: S, from?: S): boolean

Checks if you may transition to the given state.

toPlantUml(title?: string, includeFinal?): string

Returns this state machine's PlantUML diagram.

transitionTo(to: S): E | void | Promise<void>

Static Methods

gotoFn<S>(instanceGetter: () => StateMachine<S>, to: S): OnTransition<S>

Utility function to create a transition function that only immediately transitions to the given state.