Skip to content

Instantly share code, notes, and snippets.

@miladvafaeifard
Created August 28, 2019 12:39
Show Gist options
  • Save miladvafaeifard/feedac02b2cd06d76135ca6daeac8744 to your computer and use it in GitHub Desktop.
Save miladvafaeifard/feedac02b2cd06d76135ca6daeac8744 to your computer and use it in GitHub Desktop.
auto increment in generator fun and setInterval
const appDiv: HTMLElement = document.getElementById('app');
function* autoIncrement(){
let num = 0;
while (num < 11) {
yield num++;
}
}
const inc = autoIncrement();
const tm = setInterval(() => {
let next = inc.next();
if(!next.done) {
appDiv.innerHTML = (next.value).toString();
} else {
clearTimeout(tm);
}
}, 1000);
@miladvafaeifard
Copy link
Author

miladvafaeifard commented Aug 28, 2019

copy this and paste in stackblitz typescript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment