I want to run a loop parralel. What is the best practise to handle this? At this moment it is not working parralel, so it takes over sometimes 3 seconds before the fields have been proceeded by the default loop. Below my current example;
const getData = async (method, componentDispatch, componentFields, pageNumber = 1) => {
// It is necessary to wait for this call.
await store.dispatch(Actions[componentDispatch], componentInit.value.currentId).then(async () => {
const fields = JSON.parse(componentFields);
// I want to create a loop here which does NOT wait on each other, as in this loop there are other async functions, I want to run this loop next to each other on the same time.
for (let i = 0; i < fields.length; i++) {
const test = await hello();
}
})
}
const test = await hello();->const test = hello();however, it seems you've removed too much code. I would assume you need thetestvariable for something. It's hard to give an exact suggestion for incomplete code. In general you should probably usePromise.all()See:Use async await with Array.map and Using async/await with a forEach loopfor (let i = 0; i < fields.length; i++) { }as fields.length has more items in it, and have different awaits further in the loop as you can seeconst test = await hello();. I just want that if there are 4 items to loop infields, they run parralel.