withResolvers() and try()

Promise.withResolvers() and Promise.try()

Promise.withResolvers() (ECMAScript 2024, Baseline since March 2024) returns { promise, resolve, reject }, so code outside an executor can settle the promise, for example when matching worker replies to requests. Promise.try(fn, ...args) (ECMAScript 2025, Baseline since January 2025) calls fn synchronously and always returns a promise, turning a synchronous throw into a rejection. Promise.resolve(fn()) cannot, because fn() throws before resolve() is called.

Settling a promise from outside, and calling possibly-throwing code safelyJavaScriptLive
const { promise, resolve } = Promise.withResolvers();
setTimeout(() => resolve("settled from outside the executor"), 10);   // e.g. a message handler
const double = x => { if (x < 0) throw new RangeError("negative"); return x * 2; };
Promise.try(double, -1).catch(err => console.log("Promise.try caught:", err.message));
try { Promise.resolve(double(-1)); } catch { console.log("Promise.resolve() never ran"); }
console.log(await promise);

Unlike Promise.resolve().then(fn), Promise.try(fn) does not delay the call. core-js 25,536 polyfills both methods.