Answer the question
In order to leave comments, you need to log in
How to stop a loop while an async function is running?
There is an array that I go through for-rum, it is necessary to run each element through an asynchronous function and suspend the enumeration of elements until a response is received from the asynchronous function.
How can I pause the loop until the asynchronous function responds?
Example:
const arr = [1,2,3,4,5].forEach(async function(elem, index, arr) {
// передаем элемент в асинхронную функцию на обработку
// до момента ответа от асихронной функции необходимо поставить перебор на паузу
await async(elem)
})
function async(elem){
return new Promise(function(resolve, reject) {
setInterval(function() {
resolve(true)
}, 1000);
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question