Async runtime (executor and reactor)¶
Category: Scheduling · Status: stub · Lessons: chapter 06, Async (planned)
One line: The library that drives async tasks: an executor that polls the tasks that can make progress, and a reactor that wakes them when the I/O they wait for is ready.
Also called: executor, reactor, tokio, asyncio event loop.
How it connects¶
flowchart LR
n_async_runtime["Async runtime (executor and reactor)"]
n_event_loop["Event loop"]
n_io_multiplexing["I/O multiplexing"]
n_polling["Polling"]
n_work_stealing["Work stealing"]
n_async_runtime -->|uses| n_event_loop
n_async_runtime -->|uses| n_io_multiplexing
n_async_runtime -->|uses| n_polling
n_async_runtime -->|uses| n_work_stealing
classDef center stroke-width:3px
class n_async_runtime center
classDef outside stroke-dasharray: 4 3
class n_event_loop,n_io_multiplexing,n_polling,n_work_stealing outside
- Is built on: Event loop, I/O multiplexing, Polling, Work stealing
- See also: Task (async)
In each language¶
| Rust | Not in the standard library: Tokio ↗, whose #[tokio::main] starts one, is the common choice |
| Python | asyncio.run ↗ runs a coroutine in an event loop that it manages, and returns the result |
| Kotlin | runBlocking ↗ bridges regular blocking code to suspending code, blocking its thread until the coroutine completes |
Where to read more¶
- In the books: Concurrency in Go, Katherine Cox-Buday — ch. 6, 'Goroutines and the Go Runtime'
- In the books: Asynchronous Programming in Rust, Carl Fredrik Samson — ch. 6, 'Futures in Rust' → 'A mental model of an async runtime'
- In the books: Async Rust, Maxwell Flitton, Caroline Morton — ch. 3, 'Building Our Own Async Queues' → 'Configuring Our Runtime'
- In the books: Rust Programming By Example, Antoni Boucher, Guillaume Gomez — ch. 9, 'Implementing an Asynchronous FTP Server' → 'Using Tokio'
- In the books: Ultimate Rust for Systems Programming, Mahmoud Harmouch — ch. 14, 'Asynchronous Programming' → 'Utilizing the tokio Library'
- In the books: Programming Rust, Jim Blandy, Jason Orendorff, Leonora F. S. Tindall — ch. 20, 'Asynchronous Programming' → 'Primitive Futures and Executors: When Is a Future Worth Polling Again?'
- Notes: async runtimes - rust - executor ↗
- Notes: runtime - executor - async ↗
- Notes: tokio - main ↗