Callbacks

CoroutineFunc (context, *user_data)

FiberFunc (*user_data)

FutureCallback (future, *user_data)

SchedulerFunc (*user_data)

StateTransitionFunc (context, *user_data)

ThreadFunc (*user_data)

Details

Dex.CoroutineFunc(context, *user_data)
Parameters:
Returns:

a [class`Dex`.Future]

Return type:

Dex.Future or None

This function prototype is used for spawning stackless coroutines.

A coroutine function receives a [struct`Dex`.CoroutineContext] and optional user data and returns the next future for completion.

If the function returns None to indicate suspension, it must have stashed the currently awaited future in coroutine using the DEX_COROUTINE_SUSPEND_* helpers.

Dex.FiberFunc(*user_data)
Parameters:

user_data (object or None)

Returns:

a [class`Dex`.Future] or None

Return type:

Dex.Future or None

This function prototype is used for spawning fibers. A fiber is a lightweight, cooperative-multitasking feature where the fiber is given its own stack. The fiber runs until it reaches a point of suspension (using [method`Dex`.Future.await] or similar) or exits the fiber.

When suspended, the fiber is placed onto a queue until it is runnable again. Once runnable, the fiber is scheduled to run from within whatever scheduler it was created with.

See [method`Dex`.Scheduler.spawn]

Dex.FutureCallback(future, *user_data)
Parameters:
  • future (Dex.Future) – a resolved or rejected [class`Dex`.Future]

  • user_data (object or None) – closure data associated with the callback

Returns:

a [class`Dex`.Future] or None

Return type:

Dex.Future or None

A DexFutureCallback can be executed from a [class`Dex`.Block] as response to another [class`Dex`.Future] resolving or rejecting.

The callback will be executed within the scheduler environment the block is created within when using [ctor`Dex`.Future.then], ‘ctor@Dex.Future.catch [ctor@Dex.Future.finally]’, [ctor`Dex`.Future.all], and similar functions.

This is the expected way to handle completion of a future when not using [class`Dex`.Fiber] via [method`Dex`.Scheduler.spawn].

Dex.SchedulerFunc(*user_data)
Parameters:

user_data (object or None)

Dex.StateTransitionFunc(context, *user_data)
Parameters:
Returns:

True if the transition succeeded; otherwise False and error is set

Return type:

bool

Callback used to execute a transition edge.

context is opaque and only valid for the duration of the callback. It must not be stored or used after the callback returns.

Use [method`Dex`.StateTransitionContext.get_from] and [method`Dex`.StateTransitionContext.get_to] to inspect the edge that caused the callback to run. Use [method`Dex`.StateTransitionContext.get_state] and [method`Dex`.StateTransitionContext.set_state] to inspect or update the real state of the [class`Dex`.StateMachine] while the transition is running. Use [method`Dex`.StateTransitionContext.continue_to] to continue through another declared edge before queued transition requests are processed.

Dex.ThreadFunc(*user_data)
Parameters:

user_data (object or None)

Returns:

a [class`Dex`.Future]

Return type:

Dex.Future

A function which will be run on a dedicated thread.

It must return a [class`Dex`.Future] that will eventually resolve to a value or reject with error.

Added in version 1.0.