Answer the question
In order to leave comments, you need to log in
How to replace the while loop?
Good day!
The program executes the code after receiving the data. In parallel, a lot of data comes in.
The data needs to be processed. The code is written using async\await. At some point, the data needs to be processed by performing a heavy function.
The problem is that the data may come similar and then their processing is not needed, you just need to wait for the already ongoing processing of such data and take the result. At this moment, I use while with falling asleep for 100ms, followed by checking the end of execution.
You cannot continue execution until processing is completed.
How do they act in such cases? I think that this is a kind of implementation.
upd1:
Let's say the input is a numeric value. 4 input values are coming.
1)1
2)2
3)3
4)1
and for the 4th input data it is not necessary to perform a check, because it is still performed for the 1st. because of this, you have to stop the code with a loop like
while(!isChecked) {
await sleep(100) // промис возвращающийся через 100мс
}
Answer the question
In order to leave comments, you need to log in
In the simplest case, use a callback in data processing
function processData(callback){
// тяжелая обработка...
callback();
}
processData(function(){
// Данные обработаны
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question