Callbacks

FiberFunc (*user_data)

FutureCallback (future, *user_data)

SchedulerFunc (*user_data)

ThreadFunc (*user_data)

Details

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.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.

New in version 1.0.