const [resultA, resultB, resultC] = await Promise.all([getA(), getB(), getC()]);Promise.allKeyed() / notebook
Promise.allKeyed()
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const {
a: resultA,
b: resultB,
c: resultC,
} = await Promise.allKeyed({
a: getA(),
b: getB(),
c: getC(),
});function delayed(value, timeout) {
return new Promise((res) => setTimeout(() => res(value), timeout));
}
const sym = Symbol("example");
const promises = {
a: delayed("a", 500),
// Symbol properties are processed
[sym]: delayed("symbol", 300),
// Nested properties are not processed; this whole object is treated as
// an already-resolved value and returned as-is
nested: {
b: delayed("b", 100),
},
};
const result = await Promise.allKeyed(promises);
console.log(result);
// {
// a: "a",
// [sym]: "symbol",
// nested: {
// b: <Promise>,
// },
// }