Is there a way to pause a loop()? #413
-
Hi, keyPress("p", () => {
every((obj)=> {
obj.paused = !obj.paused
})
}) but any running My questions:
const myLoop = loop(3, () => {
// do something every 3 seconds
})
myLoop.paused = true // <-- same format as pausing object updates Short of this, the only way I can think of is to cancel the loop and then re-invoke it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There's no pause control at the moment. You can use let paused = false
loop(3, () => {
if (paused) return
// ...
}) To achieve pausing, however it's pausing the invocation not the timer. Currently const myLoop = loop()
myLoop.stop()
myLoop.paused = true instead of const stopLoop = loop()
stopLoop() in future versions |
Beta Was this translation helpful? Give feedback.
There's no pause control at the moment. You can use
To achieve pausing, however it's pausing the invocation not the timer.
Currently
loop()
returns a function that cancels the loop like all event handlers. It's a bit weird to have a field under a function, but I like the syntax to treat the returned thing as a general controller instead of just a function. So maybeinstead of
in future versions