Answer the question
In order to leave comments, you need to log in
How to write an asynchronous recursive function?
How can an asynchronous recursive call be implemented?
It is necessary after receiving a response from each ajax request, using the results of the previous one, send a new one, and so on until a certain condition is reached.
Answer the question
In order to leave comments, you need to log in
For example use async/await:
async function foo(val = 0) {
const response = await request(val); //предполагается, что request возвращает promise
if (response.error) throw new Error('something bad happened');
//делаем что-то с response
foo(response.newVal); //вызываем foo с новым val
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question