@vgerbot/async
    Preparing search index...

    Function concat

    • Maps over a collection and flattens the results into a single array. Each iterator should return an array, and all arrays are concatenated together.

      Type Parameters

      • I

        The type of the input items.

      • R

        The type of the elements in the returned arrays.

      Parameters

      • data: I[] | Promise<I[]>

        The collection to iterate over.

      • iteratee: (item: I, token: CancellableToken) => Promise<R[]>

        An async function that returns an array for each element.

      • Optionaloptions: ConcatOptions<R>

        Configuration options, including concurrency limit.

      Returns CancellableHandle<R[]>

      A cancellable handle that resolves to a flattened array of all results.

      const handle = concat(
      [1, 2, 3],
      async (num, token) => {
      await token.sleep(10);
      return [num, num * 2];
      },
      { concurrency: 2 },
      );

      const result = await handle; // [1, 2, 2, 4, 3, 6]
      const handle = concat(
      { a: 'hello', b: 'world' },
      async (value, key) => value.split(''),
      );

      const result = await handle; // ['h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd']
    • Maps over a collection and flattens the results into a single array. Each iterator should return an array, and all arrays are concatenated together.

      Type Parameters

      • I

        The type of the input items.

      • R

        The type of the elements in the returned arrays.

      Parameters

      • data: CollectionInput<I> | Promise<CollectionInput<I>>

        The collection to iterate over.

      • iteratee: (item: I, key: string | number, token: CancellableToken) => Promise<R[]>

        An async function that returns an array for each element.

      • Optionaloptions: ConcatOptions<R>

        Configuration options, including concurrency limit.

      Returns CancellableHandle<R[]>

      A cancellable handle that resolves to a flattened array of all results.

      const handle = concat(
      [1, 2, 3],
      async (num, token) => {
      await token.sleep(10);
      return [num, num * 2];
      },
      { concurrency: 2 },
      );

      const result = await handle; // [1, 2, 2, 4, 3, 6]
      const handle = concat(
      { a: 'hello', b: 'world' },
      async (value, key) => value.split(''),
      );

      const result = await handle; // ['h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd']