async and await

Language keywords for writing code that waits for slow work, such as a network call, without blocking a thread.

In more detail

An async function returns a task or promise straight away; each await pauses it, frees the thread for other work, and resumes it when the awaited operation completes. Neither keyword creates a thread, so async raises how much work a server keeps in flight rather than making one request faster. Errors from the awaited operation are rethrown at the await, so ordinary try-catch handles them.

Examples

public async Task<Product?> GetProductAsync(int id, CancellationToken ct)
C#: the compiler rewrites an async method as a state machine; async methods return Task or Task<T>.
In the browser: An async function always returns a promise, and await pauses that function, not the whole page, until a promise settles. The rest of the function resumes as a microtask.
export default async function Page() {
  const products = await getProducts();
  return <List items={products} />;
}
React 19 Actions are usually async functions, and startTransition accepts them directly.

Related terms

Taught in

References