I was super excited about async/await when it first came out. I hadn't really understood the point of Promises, but async/await looked simple and useful. However, I recently started using async/await in TypeScript, and the result seems to be try/catch statements everywhere. Code using async/await seems to be more verbose and unruly than just sticking to Promises, which I now appreciate the elegance of much more (call…
const delay = ms => new Promise(r => setTimeout(r, ms));
async function fooErrors() {
await delay(100);
throw new Error('I failed');
}
async function doSomething() {
await fooErrors();
}
async function main() {
try {
await doSomething();
} catch(err) {
log.fatal(err);
}
}