Callbacks¶
|
|
|
|
|
|
|
|
|
|
|
Details¶
- Dex.CoroutineFunc(context, *user_data)¶
- Parameters:
context (
Dex.CoroutineContext)
- Returns:
a [class`Dex`.Future]
- Return type:
Dex.FutureorNone
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
Noneto indicate suspension, it must have stashed the currently awaited future incoroutineusing theDEX_COROUTINE_SUSPEND_*helpers.
- Dex.FiberFunc(*user_data)¶
- Parameters:
- Returns:
a [class`Dex`.Future] or
None- Return type:
Dex.FutureorNone
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 (
objectorNone) – closure data associated with the callback
- Returns:
a [class`Dex`.Future] or
None- Return type:
Dex.FutureorNone
A
DexFutureCallbackcan 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.StateTransitionFunc(context, *user_data)¶
- Parameters:
context (
Dex.StateTransitionContext) – a [struct`Dex`.StateTransitionContext]user_data (
objectorNone) – user data provided to [ctor`Dex`.StateMachine.new]
- Returns:
Trueif the transition succeeded; otherwiseFalseand error is set- Return type:
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:
- Returns:
a [class`Dex`.Future]
- Return type:
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.