# All files / src/utils async.ts

25% Statements 1/4
100% Branches 0/0
0% Functions 0/1
33.33% Lines 1/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17

    1x

     /**
     * Applies an asynchronous function for each element in an array.
     * Each application evaluation is done sequentially. That is, an asynchronous function
     * application of an element is evaluated only when the previous applications
     * have finished.
     *
     * @param array The array to be iterated over
     * @param func The asynchronous function to be applied to each element
     * @returns A Promise that resolves once every application has been evaluated
     */
    export async function sequentialAsyncForEach<T>(array: T[], func: (arg: T) => Promise<unknown>) {
      for (let i = 0; i < array.length; i += 1) {
        // eslint-disable-next-line no-await-in-loop
        await func(array[i]);
      }
    }