-
-
Save ilearnjavascript/28afd4e5345e983f0031112d05c670e4 to your computer and use it in GitHub Desktop.
es8 - async await - 2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function resolveAfter2Seconds() { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
clearInterval(tick); | |
resolve('resolved'); | |
}, 2000); | |
}); | |
} | |
async function asyncCall() { | |
console.log('calling'); | |
var result = await resolveAfter2Seconds(); | |
console.log(result); | |
} | |
var tick = setInterval(() => console.log('tick'), 100); | |
asyncCall(); | |
// expected output: runs 20 times tick => resolved |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment