Created
June 30, 2018 06:11
-
-
Save devCola/f26ce8856c9744b7b809f7a37b81a5fe to your computer and use it in GitHub Desktop.
TS Generator example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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