Skip to content

Instantly share code, notes, and snippets.

@itacirgabral
Created October 23, 2018 19:26
Show Gist options
  • Save itacirgabral/9b40f31f261616b32a7a50f565ea4182 to your computer and use it in GitHub Desktop.
Save itacirgabral/9b40f31f261616b32a7a50f565ea4182 to your computer and use it in GitHub Desktop.
const mockFetch = url => new Promise(
res => setTimeout(
x => res(`url:${url} mockFetched`)
, 300
)
)
var arr = ["a", "e", "i", "o", "u"]
const serial_____Gen = fn => async function* serial (arr) {
for (const url of arr) {
yield fn(url)
}
}
const serialFetchGen = serial_____Gen(mockFetch)
;(async function(){
for await(const data of serialFetchGen(arr)) {
console.log(data)
}
return 'async ends'
})().then(console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment