Cheat Sheets
Async/Await · Study material
Async/Await Cheat Sheet
| Code | Meaning |
|---|---|
async function f() { return 1; } | f() → Promise<1> |
const f = async () => … · { async m() {} } | async arrow / method |
const v = await p; | wait for p's value |
try { await p; } catch (e) { … } finally { … } | handle rejection |
f().catch(handle) | handle at the call site |
await Promise.all([a(), b()]) | parallel |
for (const x of xs) await work(x); | sequential loop |
xs.forEach(async …) | does not wait |
return await p (in try) | local catch sees rejections |
for await (const v of gen()) | async iteration |
async function* gen() { yield … } | async generator |
top-level await | ES modules only |