I am not sure if its “me” or a bug or what…
Tell me if this makes sense (from a logical point of view)
I need t fire an event (via a delegate) every 1, 3 and 7 seconds
So what I did was create a class (shown here in Pseudo code)
class MyTimer {
init() { setTimer(7) } // number is seconds
// this is supposed to initialize a ONE SHOT time that waits "sec"
private func setTimer(sec : Double) {
self.delegate.timer(sec) // fire event to notifiy of current interval
let _ = Timer.scheduledTimer(withTimeInterval: color.period(), repeats: false) {_ in self.changeTimer(sec) }
}
// when time elapsed, set next interval
private changeTimer(sec:double) {
switch sec{
case 1 : t = 3
case 3 : t = 7
case 7 : t = 1
}
setTimer(t)
}
the problem is… it calls SetTimer 2x in a row (0.02 seconds apart)
so it comes out
7 7 1 1 3 3 7 7 1 1 3 3
7 seconds 0.02 seconds 1 second .02 seconds 3 seconds .02 seconds etc.
not
7 1 3 7 1 3
does anyone see a flaw in my logic