Dex.StateTransitionContext

Fields

None

Methods

continue_to (target)

get_from ()

get_state ()

get_to ()

set_state (state)

wait_for_interrupt ()

Details

class Dex.StateTransitionContext

DexStateTransitionContext is an opaque per-callback structure with information and state access for a [struct`Dex`.StateTransition] callback.

It is only valid for the duration of the callback and must not be stored.

[method`Dex`.StateTransitionContext.get_from] and [method`Dex`.StateTransitionContext.get_to] return the declared edge that caused the callback to run. [method`Dex`.StateTransitionContext.get_state] and [method`Dex`.StateTransitionContext.set_state] access the real state in the [class`Dex`.StateMachine]. Use [method`Dex`.StateTransitionContext.continue_to] to follow another declared edge before queued transition requests are processed.

Added in version 1.2.

continue_to(target)
Parameters:

target (int) – the target state for the next edge

Raises:

GLib.Error

Returns:

True if the continuation succeeded; otherwise False

Return type:

bool

Attempts to continue from the current transition to target immediately.

The continuation runs while the state machine still holds its internal serialization slot, so queued [method`Dex`.StateMachine.transition] requests are not processed first. If self has not explicitly set the state with [method`Dex`.StateTransitionContext.set_state], the current edge target is committed before the next edge is executed.

The next transition callback is called before this function returns. If that callback uses dex_await(), the same transition fiber suspends and resumes, while the state machine still holds the serialization slot. Chained continuations therefore use the normal C call stack and should be reserved for short, bounded chains rather than unbounded graph traversal.

The next edge is looked up from the real current state to target. If no such edge exists, False is returned and error is set to [error`Dex`.Error.INVALID_TRANSITION]. If the next edge callback fails, its error is propagated.

Added in version 1.2.

get_from()
Returns:

the source state for the transition edge

Return type:

int

Gets the source state for the transition edge being executed.

This value is fixed for the lifetime of self and does not change if [method`Dex`.StateTransitionContext.set_state] is called.

Added in version 1.2.

get_state()
Returns:

the current state

Return type:

int

Gets the real current state from the [class`Dex`.StateMachine].

Added in version 1.2.

get_to()
Returns:

the target state for the transition edge

Return type:

int

Gets the target state for the transition edge being executed.

This value is fixed for the lifetime of self and does not change if [method`Dex`.StateTransitionContext.set_state] is called.

Added in version 1.2.

set_state(state)
Parameters:

state (int) – the new state

Sets the real current state in the [class`Dex`.StateMachine].

This may be used by transition callbacks to expose intermediate states while doing asynchronous work. state must be a valid value in the state machine’s enum type. This method may only be used while the transition callback is active.

Added in version 1.2.

wait_for_interrupt()
Returns:

a future resolving to True when interrupted

Return type:

Dex.Future

Creates a future that resolves when the active transition context is interrupted.

This is a cooperative mechanism for long-running transition callbacks. The returned future resolves to True when [method`Dex`.StateMachine.interrupt] is called while self is active. If the context was already interrupted before this function is called, the returned future is already resolved.

If self completes before it is interrupted, the returned future is rejected with Gio.IOErrorEnum.CANCELLED.

Added in version 1.2.