Promise Cheatsheet - Async JavaScript
All essential Promise commands organized by use case, with 36+ entries you can copy and run directly. Find the right command fast when you need it.
Back to LanguagesBasics 5
new Promise((resolve, reject) => { resolve(value) })Create and resolve immediately
new Promise((resolve, reject) => { reject(new Error("fail")) })Create and reject immediately
Promise.resolve(value)Create a resolved Promise directly
Promise.reject(reason)Create a rejected Promise directly
new Promise((resolve) => setTimeout(resolve, 1000, "ok"))Resolve after a 1s delay
Consuming Promises 5
promise.then((result) => {})Register a success callback
promise.catch((error) => {})Register a failure callback
promise.finally(() => {})Run regardless of outcome
promise.then(onFulfilled, onRejected)Specify both success and failure callbacks
promise.then((v) => v + 1)then return value is auto-wrapped into a new Promise
Static Methods 5
Promise.all([p1, p2])Succeeds only if all succeed; fails if any fails
Promise.race([p1, p2])Result of the first to settle (success or fail)
Promise.allSettled([p1, p2])Wait for all to settle, return each result's status
Promise.any([p1, p2])First to succeed; fails only if all fail
Promise.allSettled result item = { status, value } or { status, reason }Result object shape
Chaining 4
fetch(url).then((r) => r.json()).then((data) => {})Chain to process the response
promise.then(() => nextPromise())Return a new Promise to sequence async work
promise.then((v) => v + 1).then((v) => console.log(v))Values pass downstream
promise.catch((err) => fallback()).then((v) => {})Recover from error then continue the chain
async/await 5
async function fn() { return value }async function auto-returns a Promise
const result = await promiseWait for the Promise to settle
try { await promise } catch (err) {}Catch rejections with try/catch
await Promise.all([p1, p2])Await multiple tasks concurrently
const [a, b] = await Promise.all([fa(), fb()])Await concurrently and destructure results
Advanced Patterns 6
for (const item of items) { await process(item) }Run serially (await one by one)
await Promise.all(items.map((i) => fetch(i)))Run all tasks concurrently
async function pool(tasks, limit) {}Limit max concurrency
Promise.race([task(), timeout(5000)])Timeout control (5s)
async function retry(fn, times = 3) {}Auto-retry on failure
async function sleep(ms) { return new Promise((r) => setTimeout(r, ms)) }Delay utility function
Cancellation & Utilities 6
const ac = new AbortController(); ac.abort()Create and trigger an abort signal
fetch(url, { signal: ac.signal })Associate the abort signal with fetch
ac.signal.addEventListener("abort", () => {})Listen for the abort event
AbortSignal.timeout(3000)Auto-abort after 3s
queueMicrotask(() => {})Push a callback into the microtask queue
const d = {}; d.promise = new Promise((r, j) => { d.resolve = r; d.reject = j })Deferred pattern (control resolve externally)
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
Commands are compiled from the official docs below. Click to verify the latest usage.
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