Skip to content

Instantly share code, notes, and snippets.

@cyan33
Created November 14, 2017 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyan33/1a7b613bd41c0203a81fce0cb3330689 to your computer and use it in GitHub Desktop.
Save cyan33/1a7b613bd41c0203a81fce0cb3330689 to your computer and use it in GitHub Desktop.
use generator function to do expensive calculation
function *count() {
var x = 1;
while (true) {
yield x++;
}
}
var gen = count()
// you could infinitely call gen.next()
gen.next()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment