Created
June 9, 2021 18:34
-
-
Save mhofman/75ba4304ff4cd4bfac45327ca0ecbe3b to your computer and use it in GitHub Desktop.
Promise.allEntries
This file contains hidden or 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
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