Delay. If 0 is given, requestAnimationFrame
is used over setTimeout
.
For Await loop every second
const loop = delayLoop(1000);
// Or: const loop = delayLoop({ secs: 1 });
for await (const o of loop) {
// Do something...
// Warning: loops forever
}
Loop runs every second
(async () => {
const loop = delayLoop(1000);
// or: loop = delayLoop({ secs: 1 });
while (true) {
await loop.next();
// Do something...
// Warning: loops forever
}
})();
Alternatives:
Async generator that loops at a given interval.