Promise await dictionary
Object-based counterparts to Promise.all and Promise.allSettled. Instead of accepting an array of promises and returning an array of results, they accept a record of promises and return a record of results under the same keys.
| Type | TC39 | CoreJS | Babel | Civet | JS+ |
|---|---|---|---|---|---|
| Polyfill | ✅ Stage 2.7 View | ❌ | ❌ | ❌ | ✅ via Custom |
Promise.allKeyed(promises)
Section titled “Promise.allKeyed(promises)”Resolves when all promises in the record have resolved, returning a record with the same keys mapped to their resolved values. Rejects immediately if any promise rejects.
const result = await Promise.allKeyed({ user: fetchUser(), settings: fetchSettings(), notifications: fetchNotifications(),});
result.user; // → resolved Userresult.settings; // → resolved Settingsresult.notifications; // → resolved Notification[]Rejects immediately if any promise rejects, just like Promise.all:
await Promise.allKeyed({ a: Promise.resolve(1), b: Promise.reject(new Error('failed')),});// ✗ Error: failedPromise.allSettledKeyed(promises)
Section titled “Promise.allSettledKeyed(promises)”const result = await Promise.allSettledKeyed({ user: fetchUser(), settings: fetchSettings(), notifications: fetchNotifications(),});
if (result.user.status === 'fulfilled') { console.log(result.user.value);} else { console.error(result.user.reason);}