It’s the cleanest way to wrap a event-emitting library, for example. async/await is not applicable in such a case where resolve needs to be explicitly called in a callback.
async function process() {
return new Promise((resolve, reject) => {
emitter.on(”error”, (err) => reject(err));
emitter.on(”end”, (result) => resolve(result));
emitter.start();
});
}
async is not strictly needed here, but I find it a good practice to use it on functions which immediately return a Promise anyway.