JSFiddle - React, Tailwind, and code Playground
by Scott Kaye
JavaScript
console.clear();
async function main() {
let i = 0;
const doThing = async () => await new Promise((resolve, reject) => {
++i;
if (i == 0) {
resolve(5);
}
if (i == 1) {
reject(10);
}
});
doThing()
.then(r => {
doThing()
.then(r => console.log("Success 1", r));
})
.catch(r => console.log("Error 1", r));
i = 0;
try {
let result = await doThing();
result = await doThing();
console.log("Success 2", result);
}
catch (e) {
console.log("Error 2", e);
}
}
main();