Skip to content

Instantly share code, notes, and snippets.

@devCola
Created June 30, 2018 06:11
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 devCola/f26ce8856c9744b7b809f7a37b81a5fe to your computer and use it in GitHub Desktop.
Save devCola/f26ce8856c9744b7b809f7a37b81a5fe to your computer and use it in GitHub Desktop.
TS Generator example
function* generateRandomNumber() {
let count = 1;
// tslint:disable
while (true) {
count++;
console.log(count);
yield Math.random();
}
}
function test() {
const generator = generateRandomNumber();
console.log(`random1: ${generator.next().value}`);
console.log('test1');
console.log(`random2: ${generator.next().value}`);
console.log('test2');
console.log(`random3: ${generator.next().value}`);
console.log('test3');
}
test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment