How do you wrap a callback-based API into a Promise?

This tests Promise constructor mechanics and callback migration. A strong answer returns a new Promise, calls the legacy function, maps success to resolve and errors to reject.
This tests whether you understand the Promise constructor as a bridge between legacy callback APIs and modern async patterns. A complete answer returns a new Promise that wraps the legacy call, passes a callback that resolves with the value on success and rejects with the error on failure, and ensures the wrapper function returns that Promise. A red flag is forgetting to handle the error case, calling resolve with an error, or returning the legacy function's undefined return value instead of the Promise object.
Read the original → developer.mozilla.org
- #promises
- #callbacks
- #async
- #javascript
- #typescript
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.