Skip to content

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

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