Skip to content
Commitwise
Menu

async/await

Writing asynchronous code that reads top to bottom like normal code, with await marking where it may pause.

Definition

With async/await, a function marked async (Swift) or suspend (Kotlin) can wait for slow work without blocking a thread. Each await is a point where the function may pause and resume later. It replaces nested callbacks with straight-line code and makes error handling work with normal try/catch.

In practice

let user = try await api.user(id: 42) in Swift waits for the request, then continues on the next line.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.