runtime.scheduler - Palamecia/mint GitHub Wiki

Module runtime.scheduler

Description

load runtime.scheduler

This module provides the Runtime.Scheduler class which coordinates asynchronous I/O operations, suspended coroutines, and readiness-driven resumption.

Packages

Classes

Runtime.Scheduler

This class manages synchronization between the asynchronous devices.

Public members

Modifiers Member Description
const complete Removes a completed promise from the running set.
const new Creates a new scheduler for asynchronous operations.
const poll Waits for I/O events on the running operation. The timeout parameter specifie...
const run Runs the synchronization loop synchronously. This loop calls Runtime.Schedule...
const runOne Runs the synchronization loop synchronously. This loop calls Runtime.Schedule...
const spawn Schedules a coroutine for execution. Returns an instance of Runtime.Scheduler...
suspend Suspends the current coroutine and registers an asynchronous operation. The o...
final const to_async_runtime Returns the pointer to the internal mint::AsyncRuntime instance.
const watch Adds an object to the scheduler. The object must provides the getHandle method. ...

Private members

Modifiers Member Description
final d_ptr Internal scheduler context pointer.
@ const g_lib Global library handle.
final operations Internal list of waiting operations.
final running Internal list of running promises.
final waiting Internal list of waiting coroutines.

Descriptions

Runtime.Scheduler.complete

def (self, promise)

Removes a completed promise from the running set.

Runtime.Scheduler.d_ptr

null

Internal scheduler context pointer.

Runtime.Scheduler.g_lib

lib ('libmint-runtime')

Global library handle.

Runtime.Scheduler.new

def (self)

Creates a new scheduler for asynchronous operations.

Runtime.Scheduler.operations

[]

Internal list of waiting operations.

Runtime.Scheduler.poll

def (self, timeout = 500)

Waits for I/O events on the running operation. The timeout parameter specifies the maximum amount of time (in milliseconds) to wait for an event. If timeout is not specified, a default value of 500 milliseconds is used. If an operation is completed, it will resume its coroutine.

Runtime.Scheduler.run

def (self, timeout = 500)

Runs the synchronization loop synchronously. This loop calls poll until all coroutines added with Runtime.Scheduler.spawn is completed. The timeout parameter is forwarded to the Runtime.Scheduler.poll method.

Runtime.Scheduler.runOne

def (self, timeout = 500)

Runs the synchronization loop synchronously. This loop calls poll until a coroutine added with Runtime.Scheduler.spawn is completed. The timeout parameter is forwarded to the Runtime.Scheduler.poll method.

Runtime.Scheduler.running

[]

Internal list of running promises.

Runtime.Scheduler.spawn

def (self, coroutine)

Schedules a coroutine for execution. Returns an instance of Runtime.Promise associated to the coroutine object.

The coroutine is added to the scheduler's ready queue and will be executed during the next iteration of the event loop.

Coroutines spawned using this method run concurrently with other scheduled coroutines.

The scheduler does not guarantee execution order beyond fairness between ready coroutines.

Runtime.Scheduler.suspend

def (self, operation)

Suspends the current coroutine and registers an asynchronous operation. The operation must implement the Runtime.Operation interface.

When invoked:

  1. The current coroutine is suspended
  2. The operation is registered with the scheduler
  3. The scheduler continues executing other coroutines

The operation is responsible for indicating when it is ready to resume. Once the required condition is met (for example, a socket becomes readable), the scheduler resumes the suspended coroutine.

The result of the operation is returned to the coroutine when it resumes.

This mechanism allows asynchronous operations to be written in a sequential style using await.

An instance of Exception.InvalidOperation is raised on error.

Runtime.Scheduler.to_async_runtime

def (self)

Returns the pointer to the internal mint::AsyncRuntime instance.

Runtime.Scheduler.waiting

[]

Internal list of waiting coroutines.

Runtime.Scheduler.watch

def (self, object)

Adds an object to the scheduler. The object must provides the getHandle method.

An instance of Exception.SystemError is raised on error.