Skip to content

Instantly share code, notes, and snippets.

@wookimiii
Last active November 20, 2018 17:14
Show Gist options
  • Save wookimiii/be441c472e60de71d7b9ab1b9174cab5 to your computer and use it in GitHub Desktop.
Save wookimiii/be441c472e60de71d7b9ab1b9174cab5 to your computer and use it in GitHub Desktop.
All Promises using an object instead of an array
function allPromises(promises) {
let keys = []
let values = []
Object.entries(promises).forEach(entry => {
keys.push(entry[0])
values.push(entry[1])
})
return Promise.all(values).then(resultsArray => {
let results = {}
resultsArray.forEach((result, index) => {
results[keys[index]] = result
})
return results
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment