I am trying to create a timer background task. I use DispatchSourceTimer
and DispatchQueue
with new methods Swift 3.
But it does not work...
var timer: DispatchSourceTimer!
let queue = DispatchQueue(label: "fr.yseemonnier.app.timer", attributes: [])
timer = DispatchSource.makeTimerSource(flags: DispatchSource.TimerFlags(rawValue: UInt(0)), queue: queue)
timer.scheduleRepeating(deadline: .now(), interval: Double(5 * NSEC_PER_SEC), leeway: .seconds(1))
timer.setEventHandler {
DispatchQueue(label: "fr.yseemonnier.app.timer.async").async {
print("Background task...") //refresh all 5 seconds...
}
}
timer.resume()
Thank you,
YM