Skip to content

Instantly share code, notes, and snippets.

@kopasetik
Last active December 19, 2016 01:30
Show Gist options
  • Save kopasetik/fca367105cb471de073d18449675554f to your computer and use it in GitHub Desktop.
Save kopasetik/fca367105cb471de073d18449675554f to your computer and use it in GitHub Desktop.
Make something streamlike out of an asynchronous call
function makeStreamyThing(array, delayInterval){
var newStreamyThing = array.map((element, index) => {
return callback => setTimeout(() => {
callback(element)
}, (index + 1) * delayInterval)
})
return newStreamyThing
}
fetch('https://www.omdbapi.com/?s=batman')
.then((res) => res.json())
.then(data => {movieData = makeStreamyThing(data.Search, 500).map(fn => {
fn(console.log)
})
})
.catch((err) => {console.error(err)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment