Standard library / async · await · on the one-page reference

async · await Native only

Experimental — the native event loop is still gaining backend coverage.

Asynchronous code runs on a native event loop. The program drains pending callbacks and promises before it exits.

APINotes
async function f(): Promise<T> { … }declares an async function
await exprawaits a Promise<T>, yields T
Promise.resolve(x)T → Promise<T>
setTimeout(fn, ms)(() => void, int) → int — schedules a callback after a delay, returns a handle
clearTimeout(id)int → void — cancels a pending setTimeout
setInterval(fn, ms)(() => void, int) → int — repeats a callback every delay until cancelled
clearInterval(id)int → void — cancels a running setInterval; the same underlying function as clearTimeout, two names to match Node