Skip to content

AsyncLoop

This is the event loop that schedules and runs every coroutine passed to it using the run method. It will create a number of consumer threads that process coroutines concurrently.

graph BT
N1["AsyncLoop"] -->|inherits| N2["Any"];

Characteristics

Quality Value
Inherits global.Any
Extends N/A
Decorators #sealed;
Is enum false
Is sealed true
Is extern false
Is abstract false
Is generator false
Has value semantics false
Has stored properties true
Should register destructor false
Has atomic memory false
Is copy assignable false
Is zero initializable false

Functions

__consumer

__consumer (loop AsyncLoop) -> Nil

__router

__router (loop AsyncLoop) -> Nil

Methods

construct

construct (s strictly @Self, concurrency: Int64 = 0) -> Self
Will fire up the event loop and all the consumer threads. The number of consumer threads is by default set to the number of hardware threads. You can set a different number by providing a positive number for concurrency.


run

run (s @Self, coro nom Coroutine) -> Future
schedules the coroutine for execution in the loop


signal

signal (s @Self) -> Nil
by default the loop checks every coroutine once. If any coroutine returns a value then the loop will schedule additional runs to recheck other coroutines. If no coroutine returns any value however it'll pause all threads waiting for an external event to signal a change.
To signal to the loop that a value has become available due to external causes you can use this function which will make the loop re-run every coroutine again looking for a change.


shutdown

shutdown (s @Self) -> Nil
Will schedule a shutdown which will eventually shutdown all consumer threads and other threads after processing remaining coroutines. No coroutine must be added after calling this function or they will not be executed.
The loop cannot be used after calling this function.


Properties

__active_q

__active_q ConcurrentQueue[nom Coroutine, SpinMutex, SpinMutex]?()

__consume_q

__consume_q ConcurrentQueue[nom Coroutine, SpinMutex, SpinMutex]?()

__sem

__sem Semaphore

__shutdown_sem

__shutdown_sem Semaphore

__concurrency

__concurrency Int64

__in_flight_coros

__in_flight_coros NInt