Crates.io | tl-async-runtime |
lib.rs | tl-async-runtime |
version | 0.1.2 |
source | src |
created_at | 2022-03-03 20:26:43.564662 |
updated_at | 2022-03-04 07:26:43.136292 |
description | A bad runtime impl for educational purposes only |
homepage | |
repository | https://github.com/conradludgate/tl-async-runtime |
max_upload_size | |
id | 543088 |
size | 56,438 |
A fairly basic runtime example in <600 lines of logic
Many.
The runtime is first created by calling the block_on
function, passing in a future.
The runtime will start up the threads and spawns the given future on the runtime.
At this point, all threads are 'workers'. Workers do a few things
The main thread does 1 extra step, which is polling the channel future returned by the initial spawn. This is so that we can exit as soon as that task has been completed.
The core of the async runtime is scheduling tasks and managing the threads.
There's only 2 steps to this:
The timers are very rudementary. When a timer is first polled, it
gets the thread-local executor object and pushes a (Time, TaskId)
pair
into a priority queue (ordered by time ascending).
The book-keepers will loop through this priority queue and send the respective task IDs into the ready queue.
Using mio, event sources are registered with the OS when they are created.
When events are requested for a specific source, a [RegistrationToken -> Sender]
entry is pushed into
a hashmap.
The book-keepers will poll the OS for new events. If a corresponding token is found in the hashmap, it will send the event along the channel. Since it's using a future-aware channel, it will auto-wake any tasks that are waiting for the event