Skip to content

Instantly share code, notes, and snippets.

@ObsidianCat
Created August 17, 2019 17:07
Show Gist options
  • Save ObsidianCat/013e1efffbe7496817bbc3024d929698 to your computer and use it in GitHub Desktop.
Save ObsidianCat/013e1efffbe7496817bbc3024d929698 to your computer and use it in GitHub Desktop.
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