This repository was archived by the owner on Nov 12, 2024. It is now read-only.
Is there a way to pause a loop()? #413
Answered
by
slmjkdbtl
oaklandgit
asked this question in
Q&A
|
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 updatesShort of this, the only way I can think of is to cancel the loop and then re-invoke it. |
Answered by
slmjkdbtl
Nov 13, 2021
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 = trueinstead of const stopLoop = loop()
stopLoop()in future versions |
1 reply
Answer selected by
oaklandgit
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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