DispatchTimer
public class DispatchTimer
DispatchTimer
is a general-purpose wrapper over the DispatchSourceTimer
mechanism in GCD.
-
The state of a
See moreDispatchTimer
.Declaration
Swift
public enum State
-
Declaration
Swift
public typealias Payload = DispatchSource.DispatchSourceHandler
-
Declaration
Swift
public static let defaultAccuracy: DispatchTimeInterval
-
Timer current state.
Declaration
Swift
private(set) public var state: State { get }
-
Initializes a new timer.
Declaration
Swift
public init(countdown: DispatchTimeInterval, repeating repetition: DispatchTimeInterval = .never, accuracy: DispatchTimeInterval = defaultAccuracy, executingOn executionQueue: DispatchQueue = .main, payload: @escaping Payload)
Parameters
countdown
The initial time interval for the timer to wait before firing off the payload for the first time.
repeating
The subsequent time interval for the timer to wait before firing off the payload an additional time. Repeats until manually stopped.
accuracy
The amount of leeway, expressed as a time interval, that the timer has in it’s timing of the payload execution. Default is 500 milliseconds.
executingOn
the queue on which the timer executes. Default is main queue.
payload
The payload that executes when the timer expires.
-
Arm the timer. Countdown will begin after this function returns.
Declaration
Swift
public func arm()
-
Re-arm the timer. Countdown will restart after this function returns.
Declaration
Swift
public func reset()
-
Disarm the timer. Countdown will stop after this function returns.
Declaration
Swift
public func disarm()