Skip to content

Instantly share code, notes, and snippets.

@ilearnjavascript
Created March 27, 2019 23:46
Show Gist options
  • Save ilearnjavascript/28afd4e5345e983f0031112d05c670e4 to your computer and use it in GitHub Desktop.
Save ilearnjavascript/28afd4e5345e983f0031112d05c670e4 to your computer and use it in GitHub Desktop.
es8 - async await - 2.js
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