Dex.Scheduler

g Dex.Object Dex.Object Dex.Scheduler Dex.Scheduler Dex.Object->Dex.Scheduler

Subclasses:

Dex.MainScheduler, Dex.ThreadPoolScheduler

Methods

Inherited:

Dex.Object (2)

class

get_default ()

class

get_thread_default ()

class

ref_thread_default ()

get_main_context ()

push (func, *func_data)

spawn (stack_size, func, *func_data)

Virtual Methods

None

Fields

None

Class Details

class Dex.Scheduler
Bases:

Dex.Object

Abstract:

Yes

DexScheduler is the base class used by schedulers.

Schedulers are responsible for ensuring asynchronous IO requests and completions are processed. They also schedule closures to be run as part of future result propagation. Additionally, they manage [class`Dex`.Fiber] execution and suspension.

Specialized schedulers such as [class`Dex`.ThreadPoolScheduler] will do this for a number of threads and dispatch new work between them.

classmethod get_default()
Returns:

a [class`Dex`.Scheduler]

Return type:

Dex.Scheduler

Gets the default scheduler for the process.

The default scheduler executes tasks within the default [struct`GLib`.MainContext]. Typically that is the main thread of the application.

classmethod get_thread_default()
Returns:

a [class`Dex`.Scheduler] or None

Return type:

Dex.Scheduler or None

Gets the default scheduler for the thread.

classmethod ref_thread_default()
Returns:

a [class`Dex`.Scheduler] or None

Return type:

Dex.Scheduler or None

Gets the thread default scheduler with the reference count incremented.

get_main_context()
Returns:

a [struct`GLib`.MainContext]

Return type:

GLib.MainContext

Gets the default main context for a scheduler.

This may be a different value depending on the calling thread.

For example, calling this on the [class`Dex`.ThreadPoolScheduler] from outside a worker thread may result in getting a shared [struct`GLib`.MainContext] for the process.

However, calling from a worker thread may give you a [struct`GLib`.MainContext] specifically for that thread.

push(func, *func_data)
Parameters:

Queues func to run on self.

spawn(stack_size, func, *func_data)
Parameters:
  • stack_size (int) – stack size in bytes or 0

  • func (Dex.FiberFunc) – a [callback`Dex`.FiberFunc]

  • func_data (object or None) – closure data for func

Returns:

a [class`Dex`.Future] that will resolve or reject when func completes (or its resulting DexFuture completes).

Return type:

Dex.Future

Request self to spawn a [class`Dex`.Fiber].

The fiber will have its own stack and cooperatively schedules among other fibers sharing the scheduler.

If stack_size is 0, it will set to a sensible default. Otherwise, it is rounded up to the nearest page size.

```c static Dex.Future * fiber_func (object data) { Gio.InputStream *stream = data; g_autoptr(GLib.Error) error = None; g_autoptr(GLib.Bytes) bytes = None;

if (!(bytes = Dex.Future.await_boxed (Dex.input_stream_read_bytes (stream, 4096, 0), &error))) return Dex.Future.new_for_error (g_steal_pointer (&error));

return dex_future_new_true (); }

Dex.Future * spawn_fiber (Gio.InputStream *stream) { return Dex.Scheduler.spawn (None, 0, fiber_func, GObject.Object.ref (stream), GObject.Object.unref); } ```