Created
October 23, 2018 19:26
-
-
Save itacirgabral/9b40f31f261616b32a7a50f565ea4182 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
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