Class (GI Class)

Dex-1DexStateMachine

Dex.StateMachine provides a serialized asynchronous state machine.

Transitions are declared up front with a static table of Dex.StateTransition entries. Requests made with Dex.StateMachine.transition are serialized through an internal Dex.Limiter with a max concurrency of one. Transition callbacks run from a fiber, so they may use dex_await() and related APIs while still appearing as synchronous functions.

Hierarchy (View Summary)

Index
  • Gets the most recent valid state requested with Dex.StateMachine.transition.

    The requested state is initialized to the initial state passed to Dex.StateMachine.new. It is updated immediately when Dex.StateMachine.transition is called with a valid target state, before that transition is run. It is not a guarantee that the transition will run or succeed, and it may differ from the current state returned by Dex.StateMachine.get_state.

    Returns number

    the most recent valid requested state

    1.2

  • Gets the current state of state_machine.

    Returns number

    the current state

  • Cooperatively interrupts the active transition callback.

    If a transition callback is currently active, its interrupt future returned by Dex.StateTransitionContext.wait_for_interrupt is resolved. This does not request a transition or change the current state; the active callback decides how to handle the interrupt.

    Returns boolean

    true if an active transition context was marked interrupted; otherwise false

    1.2

  • Requests a transition to target.

    If target is a valid value for the state machine's enum type, it becomes the requested state immediately and can be read with Dex.StateMachine.get_requested_state. The requested state is the most recent valid target passed to this method. It may differ from the current state and does not imply that the transition will succeed.

    Transition requests are serialized. The matching callback is run from a fiber and may use dex_await() to wait for asynchronous work. If the callback succeeds without calling Dex.StateTransitionContext.set_state, the state machine commits target. If the callback updates the state directly, the returned future resolves to the current state after the callback returns.

    Parameters

    • target: number

      the target state

    Returns Dex.Future

    a future resolving to the final enum state

  • Waits until state_machine enters state.

    If state_machine is already in state, the returned future is already resolved. Otherwise, the future resolves the next time the current state is set to state. This does not request a transition; use Dex.StateMachine.transition to move the state machine.

    Parameters

    • state: number

      the state to wait for

    Returns Dex.Future

    a future resolving to state

    1.2

  • Releases a reference on the given object, and decreases its reference count by one.

    If it was the last reference, the resources associated to the instance are freed.

    Returns void

Interfaces

SignalSignatures