Async Timeout Function using Promise
by greatCar
JavaScript
function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
async function asyncCall() {
alert('calling');
var result = await resolveAfter2Seconds();
alert(result);
// expected output: 'resolved'
}
asyncCall();