Asynchrony¶
Category: Foundations · Status: stub · Lessons: chapter 06, Async (planned)
One line: Starting an operation and carrying on with other work instead of waiting for it; the result arrives later, through a callback, a future, or an await.
Also called: asynchronous programming, async.
How it connects¶
flowchart LR
n_asynchrony["Asynchrony"]
n_concurrency["Concurrency"]
n_parallelism["Parallelism"]
n_asynchrony ---|vs| n_concurrency
n_asynchrony ---|vs| n_parallelism
classDef center stroke-width:3px
class n_asynchrony center
classDef outside stroke-dasharray: 4 3
class n_concurrency,n_parallelism outside
- Often confused with: Concurrency, Parallelism
- See also: Async and await, Blocking and non-blocking calls, Callback, Future and promise
In each language¶
| Rust | An async ↗ function returns a Future ↗, which does nothing until something polls it |
| Go | No async or await: code is written blocking, and when a goroutine blocks, the runtime moves the others to another thread ↗ |
| C | POSIX aio_read ↗ and its relatives |
| C++ | std::async ↗ returns a std::future; C++20 coroutines ↗ add co_await |
| Java | CompletableFuture ↗ chains stages that run when a result arrives |
| Python | asyncio ↗ with async def and await |
| C# | async and await ↗ over Task and Task<T> |
| JavaScript | Promises ↗ and async functions ↗ |
| Kotlin | Calls to suspend functions ↗ run sequentially by default; the library function async ↗ starts one concurrently and returns a Deferred |
| Swift | async functions and await ↗ |
| Erlang and Elixir | Task.async ↗ and Task.await: a process and a message underneath |
| Haskell | async and wait ↗ from the async package run an IO action in a separate thread and collect its result |
| The operating system | io_uring ↗ on Linux, with a submission queue and a completion queue; the POSIX AIO ↗ interface |
Where to read more¶
- In the books: Async Rust, Maxwell Flitton, Caroline Morton — ch. 1, 'Introduction to Async'
- In the books: Learning Concurrent Programming in Scala, Aleksandar Prokopec — ch. 4, 'Asynchronous Programming with Futures and Promises'
- In the books: Concurrent Programming on Windows, Joe Duffy — ch. 8, 'Asynchronous Programming Models'
- In the books: Using Asyncio in Python, Caleb Hattingh — ch. 1, 'Introducing Asyncio'
- In the books: Kotlin Coroutines by Tutorials, Filip Babić, Nishant Srivastava — ch. 1, 'What Is Asynchronous Programming'
- In the books: Asynchronous Programming, Theophilus Edet — ch. 1, 'Introduction to Asynchronous Programming'
- Notes: Asynchrony ↗
- Notes: Asynchronous - general ↗
- Notes: async - general - asynchronous programming ↗
- Notes: What is Async Programming and why would you do it ↗
- Notes: synchronous vs asynchronous - general ↗
- Notes: why async ↗
- Reference: Wikipedia: Asynchrony (computer programming) ↗
- Reference: Asynchronous Programming in Rust: what is async programming ↗