Skip to content

Instantly share code, notes, and snippets.

@miladvafaeifard
Created August 28, 2019 12:39
Show Gist options
  • Select an option

  • Save miladvafaeifard/feedac02b2cd06d76135ca6daeac8744 to your computer and use it in GitHub Desktop.

Select an option

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

miladvafaeifard commented Aug 28, 2019 •

Copy link
Copy Markdown
Author

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