Design Pattern: Recursive Timers

Yes there is:

var loopCount = 1
myTimer = createTimer(now.plusSeconds(loopCount), [ |
    // do stuff
    if(continue) {
        loopCount = loopCount + 1
        myTimer.reschedule(now.plusSeconds(loopCount))
    }
]

I’m 90% certain this will work as I have a memory of testing this at some point. The lambda get’s a copy of loopCount and because we are rescheduling it instead of recreating it loopCount + 1 get’s preserved until the next run of the Timer.

Don’t forget to combine DPs. They are not intended to be used in isolation. I have one Rule that uses five or six DPs in ten lines of code. :slight_smile: