try/catch is Ugly
// async function
async function waitSeries(ms) {
const p1 = await pWait(ms);
console.log(`waited ${ p1 }ms`);
const p2 = await pWait(p1 + 100);
console.log(`waited ${ p2 }ms`);
const p3 = await pWait(p2 + 100);
console.log(`waited ${ p3 }ms`);
}
// higher-order function handle errors
function catchErrors(fn) {
return function(...args) {
return fn(...args).catch(err => {
console.log('ERROR', err);
});
}
}
// top-level await
await catchErrors(waitSeries)(100);