Skip to content

Instantly share code, notes, and snippets.

@mojaray2k
Created May 11, 2020 17:16
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 mojaray2k/9d4c338adbe83ca71895a6d59a52b66d to your computer and use it in GitHub Desktop.
Save mojaray2k/9d4c338adbe83ca71895a6d59a52b66d to your computer and use it in GitHub Desktop.
Create a simple Function Generator Gist

Sample Function Generator

Without while true loop

function* testing() {
    yield 1;
    yield 2;
    yield 3;
}

const iterator = testing();
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());

With while true loop

function* testing() {
  while (true) {
    yield 1;
    yield 2;
    yield 3;
  }
}

const iterator = testing();
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment