Convert Callback To Async/Await

coding · Cursor · free

Rewrite this callback based code as async/await without changing behavior. Deliver: 1. The rewritten function(s) — proper types, no any 2. A util.promisify wrapper for any Node stdlib callback that lacks a promise version 3. Error handling preserved — if the original swallowed errors, mark it and DO NOT keep the bug silently 4. Parallelism preserved — if the original fired N callbacks concurrently, use Promise.all / Promise.allSettled; don't accidentally serialize 5. Backpressure preserved — if it was streaming, keep it a stream, don't buffer into memory 6. The specific gotchas fixed: forEach with an async callback (silently doesn't await) Uncaught rejections from top level async IIFEs try/catch around a fire and forget .then() Losing this binding 7. A diff summary — what changed, what stayed 8. A test that would pass before AND after the rewrite (proves no behavior change) Node version target: [20+]. If any callback API has no promise wrapper, propose the boundary function.

#refactoring #async #javascript