For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/promise/allKeyed.md.

allKeyed es-toolkit

Resolves an object of promises concurrently, returning an object with the same keys and resolved values.

// a is the async result of doA(), b is the async result of doB()
const { a, b } = await allKeyed({ a: doA(), b: doB() });

Usage

allKeyed(tasks)

Use allKeyed when you want to run multiple promises in parallel and access results by name instead of positional indices. Similar to Promise.all, but accepts an object of promises and preserves keys in the result.

Based on the TC39 Promise.allKeyed proposal.

import { allKeyed } from 'es-toolkit/promise';

const { user, posts } = await allKeyed({
  user: fetchUser(),
  posts: fetchPosts(),
});

Plain values are also supported alongside promises.

const result = await allKeyed({
  a: Promise.resolve(1),
  b: 2,
});
// { a: 1, b: 2 }

It's also useful when you want to fetch multiple resources in parallel without worrying about array ordering.

// With Promise.all, swapping the order silently breaks destructuring:
// const [user, posts] = await Promise.all([fetchUser(), fetchPosts()]);

// With allKeyed, keys are explicit — no ordering bugs:
const { user, posts } = await allKeyed({
  user: fetchUser(),
  posts: fetchPosts(),
});

Parameters

tasksTrequired

An object whose values are promises (or plain values) to resolve concurrently.

Returns

A promise that resolves to an object with the same keys and resolved values.

Promise<{ [K in keyof T]: Awaited<T[K]> }>
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.