Skip to content

Instantly share code, notes, and snippets.

@sebringj
Last active May 3, 2017 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebringj/454cadc7773d5fcd13eaa740b077e63f to your computer and use it in GitHub Desktop.
Save sebringj/454cadc7773d5fcd13eaa740b077e63f to your computer and use it in GitHub Desktop.
maps Promise.all
async function promiseMapAll(promiseMap) {
const keys = Object.keys(promiseMap);
const promises = keys.map(key => promiseMap[key]);
const promisesArr = await Promise.all(promises);
let objMapped = {};
keys.forEach((key, i) => {
objMapped[key] = promisesArr[i];
});
return objMapped;
}
@rtm
Copy link

rtm commented May 3, 2017

Why not use Object.values()? As far as a name goes, promiseMapAll is not horrible, but how about promiseAllObject?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment