Promise Cheatsheet - Async JavaScript
This reference is for JavaScript developers writing async code, whether in the browser with fetch or in Node. It starts from creating and consuming a promise, then static combinators — all vs race vs allSettled vs any, which beginners often mix up — before chaining and the async/await sugar it sits on. Later sections cover real problems: running many requests concurrently without flooding, waiting for the fastest result with a timeout, retrying a flaky request, and aborting an in-flight fetch with AbortController. After reading you should be able to sequence async steps, run parallel tasks with a concurrency cap, and add timeout and retry to brittle calls.
Basics 5
new Promise((resolve, reject) => { resolve(value) })new Promise((resolve, reject) => { reject(new Error("fail")) })Promise.resolve(value)Promise.reject(reason)new Promise((resolve) => setTimeout(resolve, 1000, "ok"))Consuming Promises 5
promise.then((result) => {})promise.catch((error) => {})promise.finally(() => {})promise.then(onFulfilled, onRejected)promise.then((v) => v + 1)Static Methods 5
Promise.all([p1, p2])Promise.race([p1, p2])Promise.allSettled([p1, p2])Promise.any([p1, p2])Promise.allSettled result item = { status, value } or { status, reason }Chaining 4
fetch(url).then((r) => r.json()).then((data) => {})promise.then(() => nextPromise())promise.then((v) => v + 1).then((v) => console.log(v))promise.catch((err) => fallback()).then((v) => {})async/await 5
async function fn() { return value }const result = await promisetry { await promise } catch (err) {}await Promise.all([p1, p2])const [a, b] = await Promise.all([fa(), fb()])Advanced Patterns 6
for (const item of items) { await process(item) }await Promise.all(items.map((i) => fetch(i)))async function pool(tasks, limit) {}Promise.race([task(), timeout(5000)])async function retry(fn, times = 3) {}async function sleep(ms) { return new Promise((r) => setTimeout(r, ms)) }Cancellation & Utilities 6
const ac = new AbortController(); ac.abort()fetch(url, { signal: ac.signal })ac.signal.addEventListener("abort", () => {})AbortSignal.timeout(3000)queueMicrotask(() => {})const d = {}; d.promise = new Promise((r, j) => { d.resolve = r; d.reject = j })Tips
- A Promise has three states: pending, fulfilled, rejected - irreversible once settled.
- then returns a new Promise; chained return values are auto-wrapped and passed to the next then.
- catch equals then(null, onRejected) and catches rejections anywhere in the chain.
- Use all when all must succeed, allSettled when you need every result, race for the fastest, any for the first success.
- async/await is syntactic sugar over Promises; try/catch makes error handling clearer.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us