0

In the nested loops I have async await. For me it is important that on each iteration loop will wait until await will be finished/data received and the start next iteration.

const _sampleFilters = async (
  pageName,
  details,
  available,
) => {
  for (const filterName of Object.keys(details)) {
    for (const filterValue of Object.keys(details[filterName])) {
      const data = (await fetchDetails(
        pageName
      ));

      details[filterName][filterValue].allDetails = cloneDeep(
        getProcessedData(
          data.map(data => data.value),
          available,
          pageName,
        ),
      );
    }
  }
};
  • The `for ... of` loop should work, try opening a new question about that – Christian Vincenzo Traina Feb 16 '22 at 21:20
  • Dear @CristianTraìna I tried this one, but also does not help const _sampleFilters = async ( pageName, details, available, ) => { for (const filterName of Object.keys(details)) { for (const filterValue of Object.keys(details[filterName])) { const data = (await fetchDetails( pageName )); details[filterName][filterValue].allDetails = cloneDeep( getProcessedData( data.map(data => data.value), available, pageName, ), ); } } }; – Narek Keshishyan Feb 17 '22 at 04:41
  • https://stackoverflow.com/questions/71152670/why-in-the-nested-loops-await-not-wait – Narek Keshishyan Feb 17 '22 at 04:53

0 Answers0