Created
February 16, 2018 18:07
-
-
Save Walexander/ecff218df985412220fa466e95ff309f 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
var a = { | |
foo: [ 'foo1', 'foo2' ], | |
bar: [ 'bar1', 'bar2' ], | |
} | |
Object.keys( a ).map( (list) => a[list] ) | |
.reduce( (accum, current) => { | |
return accum.then( () => { | |
var promises = current.map( (url) => load(url) ) | |
return Promise.all(promises) | |
}) | |
}, Promise.resolve() ) | |
function load(url) { | |
console.log(`loading url ${url}`) | |
return new Promise( (resolve, reject) => { | |
setTimeout(() => { resolve(url) }, 1000) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment