SyntaxStudy
Sign Up
JavaScript Intermediate 4 min read

Async Anti-Patterns

Async Anti-Patterns

Avoid the explicit Promise constructor anti-pattern, await in loops, and swallowing errors.

Example
// Bad: wrapping already-thenable in new Promise
async function bad() { return new Promise(r => r(fetch("/api"))); }
// Good: just return the fetch
async function good() { return fetch("/api"); }
// Bad: sequential awaits in loop (slow)
for (const id of ids) { await processItem(id); }
// Good: parallel
await Promise.all(ids.map(processItem));
// Bad: swallow errors
p.catch(() => {}); // silent failure!
Pro Tip

Sequential await in a loop is O(n * latency); Promise.all is O(max latency).