Skip to content

Instantly share code, notes, and snippets.

@kentac55
Created May 18, 2020 15:38
Show Gist options
  • Select an option

  • Save kentac55/939ccec4e555863bd24d3a657a69c0ba to your computer and use it in GitHub Desktop.

Select an option

Save kentac55/939ccec4e555863bd24d3a657a69c0ba to your computer and use it in GitHub Desktop.
function timer() {
return new Promise(resolve => setTimeout(_ => resolve(), 1000))
}
async function* asyncGenerator(c) {
var i = 0;
while (i < c) {
await timer()
yield i++;
}
}
(async function() {
for await (num of asyncGenerator(3)) {
console.log(num);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment