Dex.Scheduler¶
- Subclasses:
Methods¶
- Inherited:
class |
|
class |
|
class |
|
|
|
|
Virtual Methods¶
None
Fields¶
None
Class Details¶
- class Dex.Scheduler¶
- Bases:
- Abstract:
Yes
DexScheduleris 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:
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:
Gets the default scheduler for the thread.
- classmethod ref_thread_default()¶
- Returns:
a [class`Dex`.Scheduler] or
None- Return type:
Gets the thread default scheduler with the reference count incremented.
- get_main_context()¶
- Returns:
a [struct`GLib`.MainContext]
- Return type:
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:
func (
Dex.SchedulerFunc) – the function callback
Queues func to run on self.
- spawn(stack_size, func, *func_data)¶
- Parameters:
stack_size (
int) – stack size in bytes or 0func (
Dex.FiberFunc) – a [callback`Dex`.FiberFunc]
- Returns:
a [class`Dex`.Future] that will resolve or reject when func completes (or its resulting
DexFuturecompletes).- Return type:
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 (objectdata) {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))) returnDex.Future.new_for_error(g_steal_pointer (&error));…
return dex_future_new_true (); }
Dex.Future* spawn_fiber (Gio.InputStream*stream) { returnDex.Scheduler.spawn(None, 0, fiber_func,GObject.Object.ref(stream),GObject.Object.unref); } ```