Created
August 17, 2019 17:07
-
-
Save ObsidianCat/013e1efffbe7496817bbc3024d929698 to your computer and use it in GitHub Desktop.
This file contains 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 delayedRandom(){ | |
const random = Math.random(); | |
return new Promise(resolve => setTimeout(()=>resolve(random), 100)); | |
} | |
async function* generateDelayedRandoms(){ | |
let num; | |
num = await delayedRandom() | |
yield 'One ' + num; | |
num = await delayedRandom() | |
yield 'Two ' + num; | |
num = await delayedRandom() | |
yield 'Three ' + num; | |
}; | |
async function yeldRandomResults(){ | |
for await (let v of generateDelayedRandoms()){ | |
console.log(v); | |
} | |
} | |
yeldRandomResults(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment