Answer the question
In order to leave comments, you need to log in
How to pause a loop?
Is it possible in JS, without using setTimeout, setInterval to accomplish this task:
while(true) {
open(function() {
/* async код, который выполняется всегда разное кол. времени */
cycleContinue()
});
cycleSuspend()
}
Answer the question
In order to leave comments, you need to log in
const randomDelay = () => new Promise(resolve => setTimeout(resolve, Math.random()*1000));
(async function() {
let counter = 0;
while (true) {
console.time('timer');
await randomDelay();
console.timeEnd('timer');
if (counter++ > 20) {
break;
}
}
})();
if it’s paused, then it’s best to rewrite the async code to sync code, of course
you can try
open(async function() {
/* async код, который выполняется всегда разное кол. времени */
await myAsyncCode()
.....
cycleContinue()
});
I think that you can also put break, but you will have an exit from the loop, and then you can just call it again
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question