Async/await example with promises
const asyncTask = () =>
new Promise((_resolve, reject) =>
setTimeout(() => reject("Something not working!"), 1e3)
);
const foo = () =>
asyncTask()
.then(console.log) // Logs Promise
.catch(console.error) // Logs the failure
.finally(() => console.log("After calling AsyncTask")); // Logs the completion
foo();