Skip to content

Instantly share code, notes, and snippets.

@mhofman
Created June 9, 2021 18:34
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 mhofman/75ba4304ff4cd4bfac45327ca0ecbe3b to your computer and use it in GitHub Desktop.
Save mhofman/75ba4304ff4cd4bfac45327ca0ecbe3b to your computer and use it in GitHub Desktop.
Promise.allEntries
Promise.allEntries = (entries) =>
Promise.all(Array.from(entries).map((entry) => Promise.all(entry)));
const obj = {
foo: Promise.resolve("bar"),
};
const resolvedObject = Object.fromEntries(
await Promise.allEntries(Object.entries(obj))
);
const map = new Map();
map.set(Promise.resolve("foo"), Promise.resolve("bar"));
const resolvedMap = new Map(await Promise.allEntries(map.entries()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment