INNER CODE UNIT · TypeScript

promiseAllWithErrors

austin-starks/Promptimizer · src/utils/index.ts:94

export async function promiseAllWithErrors<T>(
  promises: Promise<T>[]
): Promise<T[]> {
  const results = await Promise.allSettled(promises);

  const fulfilled: T[] = [];
  const errors: string[] = [];

  results.forEach((result) => {
    if (result.status === "fulfilled") {
      fulfilled.push(result.value);
    } else {
      errors.push(result.reason);
    }
  });

  if (errors.length > 0) {
    throw new PromiseAllWithErrorsError(fulfilled, errors);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…