Snippet · Writing & changing code
Modernise old async code
Callbacks to promises, without changing behaviour.
This uses callbacks and I'd like promises and async/await: <paste> Convert it, keeping behaviour identical: - Errors that arrived as a first callback argument become rejections. - Preserve the ordering. If operations ran sequentially, they must stay sequential — don't parallelise them as a "bonus". - Anything that ran in parallel by accident, flag it rather than quietly changing it. - Add the error handling the callback version was missing. List every behavioural difference between the two versions, including subtle ones around ordering and error timing.
The risk in this conversion is accidental parallelism. Code that happened to be sequential can develop race conditions the moment it isn't.