huridocs/uwazi

View on GitHub
app/shared/data_utils/promiseUtils.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
const syncedPromiseLoop = async <T>(
  arr: T[],
  promiseFunc: (curr: T, index: number) => Promise<boolean | void>
): Promise<void> => {
  let index = 0;
  let continueLoop = true;
  while (index < arr.length && continueLoop) {
    // eslint-disable-next-line no-await-in-loop
    continueLoop = (await promiseFunc(arr[index], index)) !== false;
    index += 1;
  }
};

export { syncedPromiseLoop };