Search code examples
iosswiftdispatch-queue

Behaviour of calling scheduleRepeating() on running DispatchSourceTimer?


I have a running DispatchSourceTimer that is created with:

self.timer = DispatchSource.makeTimerSource(flags: .init(rawValue: 0), queue: self.myQueue)
self.timer!.scheduleRepeating(deadline: .now(), interval: .milliseconds(100))
self.timer!.setEventHandler(handler: self.myHandler)

What happens when I call:

self.timer!.scheduleRepeating(deadline: .now(), interval: .milliseconds(100))

at a later time? Does it reset the timer and make it start 'counting milliseconds' again?

The iOS documentation explains nothing.


Solution

  • Short answer:

    Yes, it resets the timer and makes it start again


    You could test it yourself in a Playground ...