Skip to content
uencoder

Async/Await

async/await writes asynchronous code with synchronous syntax: an async function returns a Promise, and await suspends execution until the Promise settles.

Purpose

Simplify asynchronous code with synchronous-style syntax, eliminating then chains and improving readability.

Mechanism

An async function implicitly wraps its return value in a Promise. await suspends the function (without blocking the thread) until the Promise resolves. Errors are handled with try/catch. Essentially syntactic sugar over Promises.

Use cases

  • Asynchronous programming
  • API calls
  • Error handling

References