tezvyn:

The Promise Constructor: Wrapping Old Callbacks

Source: developer.mozilla.orgintermediate

The `Promise` constructor turns old callback-style functions into modern promises you can `await`. Use it to "promisify" APIs like `setTimeout` that don't return promises. The footgun is wrapping already-promise-based code, creating unnecessary complexity.

The `Promise` constructor is a wrapper, turning old callback-style functions into modern promises you can `await`. It's your bridge from the callback-hell of the past to clean `async/await` syntax. Use it for legacy APIs like `fs.readFile` or `setTimeout` that predate native promises. The biggest footgun is wrapping code that already returns a promise, creating a needless and error-prone "Promise wrapper" anti-pattern.

Read the original → developer.mozilla.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

The Promise Constructor: Wrapping Old Callbacks · Tezvyn