Skip to content

resolveRecord

Resolves an array of keys into a record by calling an async mapper for each key. All mapper calls run concurrently via Promise.all.

Unlike parallel, which returns an array, resolveRecord preserves the key-to-value relationship in the result.

Available since v2.0.0

import { resolveRecord } from '@helpers4/promise';
// or, from the all-in-one package (same code, one install):
import { resolveRecord } from 'helpers4/promise';
resolveRecord<K extends PropertyKey, V>(keys: readonly K[], mapper: function): Promise<Record<K, V>>
ParameterTypeDescription
keysreadonly K[]The keys to resolve
mapperfunctionAsync function called for each key, returning the associated value

Promise<Record<K, V>> — A record mapping each key to its resolved value

All mapper calls run in parallel via Promise.all.

const stars = await resolveRecord(
  ['helpers4/typescript', 'helpers4/devcontainer'],
  async (repo) => fetchRepoStars(repo)
);
// => { 'helpers4/typescript': 42, 'helpers4/devcontainer': 17 }

View source on GitHub