Skip to content

Task (async)

Category: Units of execution · Status: stub · Lessons: chapter 06, Async (planned)

One line: A unit of async work handed to a runtime — a future being driven to completion — far cheaper than a thread because it holds no stack of its own while it waits.

Also called: task, spawned future.

How it connects

flowchart LR
  n_future_and_promise["Future and promise"]
  n_async_task["Task (async)"]
  n_thread["Thread"]
  n_async_task ---|vs| n_thread
  n_async_task -->|uses| n_future_and_promise
  classDef center stroke-width:3px
  class n_async_task center
  classDef outside stroke-dasharray: 4 3
  class n_future_and_promise,n_thread outside

In each language

Rust tokio::spawn hands a future to the Tokio runtime and returns a JoinHandle
Python asyncio.create_task; keep a reference to the task, since the event loop holds only a weak one
C# Task represents an asynchronous operation
JavaScript Calling an async function ↗ runs it synchronously up to its first await and returns a Promise
Kotlin async returns a Deferred with a result; launch returns a Job
Swift Task, a unit of asynchronous work
Erlang and Elixir Task.async starts a process linked to the caller, and Task.await receives its reply
Haskell async runs an IO action in a separate thread and returns an Async handle

Where to read more