Dev Tools · 1h ago
Promise.withResolvers: ES2024's Cleaner Way to Defer Promises
ES2024 introduces Promise.withResolvers, a static method that returns a promise along with its resolve and reject functions in one line. This replaces the common pattern of manually escaping the Promise constructor's callbacks, which was error-prone and verbose. The new API is already available in Node.js 22 and modern browsers, making deferred promise patterns explicit and concise.
Meridian48 take
A small but welcome quality-of-life improvement that eliminates a longstanding code smell in JavaScript, though it's unlikely to change how most developers write async code day-to-day.
Read the full reporting
You keep escaping the Promise constructor. `Promise.withResolvers` does it right. →
DEV Community
javascriptpromises