Answer the question
In order to leave comments, you need to log in
How to wait for the execution of a cyclic function?
Good day! City of some wild crutch, as it seems to me.
The goal is to wait for the execution of the data in batches and, based on the results, do something. You can't just use await'om some function there.
I tried to do it through this construction:
When data arrives, we add it to the pool of the current iteration and wait for the promise after requestPull[currentRequestNumber]["promise"]. After that, we pull out the result that belongs to the data.
The problem is that sometimes new data arrives in the process of execution. They are added to the current pool, but the data is already being processed. Because of this, they will not be in the cut. When returning a promise, when trying to get a result with this data, it will be undefined. And that data is lost.
How to transform the structure or how to redo everything? (
requestPull[currentRequestNumber] = {
"currentRequestNumber": currentRequestNumber, //текущий номер итерации
"promise": run(), //возвращает промис при выполнение
"data": [] //входные данные
"result": {} //результат выполнение run() для каждых данных
}
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