Skip to content
This repository has been 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
Discussion options

You must be logged in to vote

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 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 maybe

const myLoop = loop()

myLoop.stop()
myLoop.paused = true

instead of

const stopLoop = loop()
stopLoop()

in future versions

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@oaklandgit
Comment options

Answer selected by oaklandgit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants