JSFiddle - React, Tailwind, and code Playground
by hjleee
JavaScript
function resolveAfter2Seconds() {
return new Promise((resolve,reject) => {
setTimeout(() => {
reject('reject');
}, 2000);
});
}
async function asyncCall() {
console.log('calling');
try{
const result = await resolveAfter2Seconds();
console.log(result);
}catch(err){
console.log(err);
}
// expected output: "resolved"
}
asyncCall();