I have a function that is launched as a goroutine:
func (bt *BlinkyTape) finiteLoop(frames []Frame, repeat int, delay time.Duration) {
bt.isPlaying = true
L:
for i := 0; i < repeat; i++ {
select {
case <-bt.stop:
break L
default:
bt.playFrames(frames, delay)
}
}
bt.isPlaying = false
}
This function uses channels so it is possible to break the loop (loop can be finite or infinite)
What I would like to implement is a way to pause the execution of the loop and of course being able to resume it.
I was thinking to add another case to the select condition where I listen on another channel pause
. If the case is executed, it enter in a new infinite loop that does nothing. Then it will need the same system as previously with a resume
channel to break this loop.
What do you think ? Is there a better way to achieve what I need ?
Regards