在 运行 DispatchSourceTimer 上调用 scheduleRepeating() 的行为?
Behaviour of calling scheduleRepeating() on running DispatchSourceTimer?
我有一个 运行 DispatchSourceTimer
是用以下方法创建的:
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)
我打电话时会发生什么:
self.timer!.scheduleRepeating(deadline: .now(), interval: .milliseconds(100))
稍后?它会重置计时器并使其再次启动 'counting milliseconds' 吗?
iOS documentation 什么也没解释。
简答:
是的,它会重置计时器并使其重新启动
您可以在 Playground 中自行测试...
我有一个 运行 DispatchSourceTimer
是用以下方法创建的:
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)
我打电话时会发生什么:
self.timer!.scheduleRepeating(deadline: .now(), interval: .milliseconds(100))
稍后?它会重置计时器并使其再次启动 'counting milliseconds' 吗?
iOS documentation 什么也没解释。
简答:
是的,它会重置计时器并使其重新启动
您可以在 Playground 中自行测试...