Is it an anti-pattern to use async/await inside of a new Promise() constructor? Is it an anti-pattern to use async/await inside of a new Promise() constructor? javascript javascript

Is it an anti-pattern to use async/await inside of a new Promise() constructor?


You're effectively using promises inside the promise constructor executor function, so this the Promise constructor anti-pattern.

Your code is a good example of the main risk: not propagating all errors safely. Read why there.

In addition, the use of async/await can make the same traps even more surprising. Compare:

let p = new Promise(resolve => {  ""(); // TypeError  resolve();});(async () => {  await p;})().catch(e => console.log("Caught: " + e)); // Catches it.