-
Notifications
You must be signed in to change notification settings - Fork 0
AsyncTimer
The timer can be used to execute periodically provided block on any queue (main, private). It allows scheduling resume, suspend and restart operations in future (at specific date, or after given elapsed time) It also supports loop mode, in which it will restart after a given interval It can be in 2 states - running and suspended
public class AsyncTimer: AsyncTimerPInits timer ready to resume with given interval, startDelay and handler
public init(interval: Double, startDelay: Double? = nil, _ queue: DispatchQueue = .main, _ handler: @escaping AsyncTimerBlock)- interval: frequency of executing the handler, in seconds (rounded to milliseconds)
- startDelay: delay interval of start, in seconds (rounded to milliseconds)
var state: TimerState = .suspendedFrequency of executing the handler Interval is in seconds (rounded to milliseconds)
var interval: DoubleDelay interval for each resume operation Interval is in seconds (rounded to milliseconds)
var startDelay: DoubleTime elapsed since timer was (re)started Interval is in seconds (rounded to milliseconds)
var elapsedTime: Double = 0.0var observer: AsyncTimerObserverP?When set - suspends timer when elapsed time reaches this value (and this setting is the reset to nil) Time is in seconds (rounded to milliseconds)
var autoStopOnElapsedTime: Double?When set timer works in loop mode, by restarting when the elapsedTime reaches the value of loopInterval Interval is in seconds (rounded to milliseconds)
var loopInterval: Double?When set - suspends timer when this date is reached (and this setting is the reset to nil) Interval is in seconds (rounded to milliseconds)
var autoStopOnDate: Date?Sets timer to work in loop mode, by restarting when the elapsedTime reaches the value of loopInterval
public func setLoopInterval(_ interval: Double)- elapsedTime: time interval in seconds (rounded to milliseconds)
Resumes currently suspended timer with given paramaters
@discardableResult public func resume(interval: Double? = nil, after startDelay: Double? = nil, _ handler: (AsyncTimerBlock)? = nil) -> Bool- interval: frequency of executing the handler, in seconds (rounded to milliseconds)
- startDelay: startDelay, in seconds (rounded to milliseconds)
true if succeeded
Resumes timer, if it's suspended
@discardableResult public func resume(after delayInterval: Double) -> Bool- delayInterval: delayInterval, in seconds (rounded to milliseconds)
true if succeeded
Schedules resuming timer when this date is reached, if it's suspended
@discardableResult public func resume(on date: Date) -> Booltrue if succeeded
Schedules resuming timer when elapsed time reaches this value, if it's suspended
@discardableResult public func resume(on elapsedTime: Double) -> Bool- elapsedTime: elapsedTime, in seconds (rounded to milliseconds)
true if succeeded
Suspends timer if it's running
@discardableResult public func suspend() -> Booltrue if succeeded
Schedules suspending timer when this date is reached
@discardableResult public func suspend(on date: Date) -> Bool- interval: frequency of executing the handler, in seconds (rounded to milliseconds)
true if succeeded
Suspends timer if it's running, after given interval
@discardableResult public func suspend(after delayInterval: Double) -> Bool- delayInterval: delayInterval, in seconds (rounded to milliseconds)
true if succeeded
Schedules suspending timer when elapsed time reaches this value, if it's running
@discardableResult public func suspend(on elapsedTime: Double) -> Bool- elapsedTime: elapsed time interval in seconds (rounded to milliseconds)
true if succeeded
Suspends currently running timer and starts again If interval or handler not given - reuses the last used ones
@discardableResult public func restart(interval: Double? = nil, startDelay: Double? = nil, _ handler: (AsyncTimerBlock)? = nil) -> Bool- interval: frequency of executing the handler, in seconds (rounded to milliseconds)
- startDelay: startDelay, in seconds (rounded to milliseconds)
true if succeeded
Schedules restarting timer when this date is reached
public func restart(on date: Date) -> Booltrue if succeeded
Schedules restarting timer when elapsed time reaches this value
public func restart(on elapsedTime: Double) -> Bool- elapsedTime: elapsedTime, in seconds (rounded to milliseconds)
true if succeeded
Schedules restarting timer after given interval (in seconds)
public func restart(after interval: Double) -> Bool- interval: delay interval, in seconds (rounded to milliseconds)
true if succeeded
Starts running timer in loop mode with given interval Timer must be in suspended state to run in loop mode
@discardableResult public func loop(interval: Double) -> Booltrue if succeeded
Sets handler for this timer on main queue
public func setHandler(_ handler: @escaping AsyncTimerBlock)Sets handler for this timer on given queue
public func setHandler(_ handler: @escaping AsyncTimerBlock, _ queue: DispatchQueue)If startDelay is not nil will delay start by given number of seconds.
@discardableResult public func setTimeInterval(_ interval: Double, startDelay: Double? = nil) -> Bool- interval: frequency of executing the handler, in seconds (rounded to milliseconds)
- startDelay: startDelay, in seconds (rounded to milliseconds)
true if succeeded
Sets startDelay interval, which will delay each resume operation by a given number of seconds
@discardableResult public func delayStart(by delayInterval: Double) -> Bool- delayInterval: time interval for delay of start in seconds (rounded to milliseconds)
true if succeeded
Suspends timer if it's running, and resets settings (loop, autoStop, restart)
public func resetSettings()Generated at 2020-12-27T23:23:55+0200 using swift-doc 1.0.0-beta.5.