TS-Scribe - v1.2.0
    Preparing search index...

    Function asyncFilterSettled

    • Asynchronously filters an array with an asynchronous predicate, collecting both results and errors. Unlike asyncFilter, this function never throws due to predicate errors — failed items are excluded from results and their errors are collected in the returned errors array.

      Use this when you want all items evaluated regardless of individual failures.

      Type Parameters

      • T

        The type of elements in the input array

      Parameters

      • array: T[]

        The array of elements to filter.

      • predicate: (element: T, index: number, array: T[]) => Promise<boolean>

        The asynchronous predicate function.

      • Optionaloptions: { concurrency?: number; signal?: AbortSignal } = {}

        Optional configuration

        • Optionalconcurrency?: number

          Maximum number of concurrent operations

        • Optionalsignal?: AbortSignal

          AbortSignal to cancel processing.

      Returns Promise<AsyncFilterSettledResult<T>>

      Promise resolving to an object with results and errors.

      If concurrency is not a positive integer.

      If the input array is null or undefined.

      If the signal is aborted.

      const urls = ['url1', 'url2', 'url3'];
      const { results, errors } = await asyncFilterSettled(urls, async (url) => {
      const response = await fetch(url);
      return response.ok;
      });
      // results: reachable URLs
      // errors: fetch failures with their indices