Commit 337d97d3 by Sarkizz

添加延迟执行扩展

parent 9b9cff45
...@@ -125,6 +125,26 @@ extension TimeInterval { ...@@ -125,6 +125,26 @@ extension TimeInterval {
public func `repeat`(_ handler: @escaping CountdownRepeatingBlock) -> Countdown { public func `repeat`(_ handler: @escaping CountdownRepeatingBlock) -> Countdown {
return Countdown(repeatInSec: self).repeat(handler) return Countdown(repeatInSec: self).repeat(handler)
} }
public func asyncAfterSec(_ inQueue: DispatchQueue = .main, execute: @escaping () -> Void) {
inQueue.asyncAfter(deadline: .now() + .seconds(Int(self)), execute: execute)
}
public func asyncAfterMilliSec(_ inQueue: DispatchQueue = .main, execute: @escaping () -> Void) {
inQueue.asyncAfter(deadline: .now() + .milliseconds(Int(self)), execute: execute)
}
}
extension DispatchTimeInterval {
public func asyncAfter(_ inQueue: DispatchQueue = .main, execute: @escaping () -> Void) {
inQueue.asyncAfter(deadline: .now() + self, execute: execute)
}
}
extension Int {
public func countup(stop: CountdownSecUpStopBlock?, handler: @escaping CountdownHandler) -> Countdown {
return Countdown().limitCound(self).inSecond(.up(1, stop)).handler(handler)
}
} }
public enum CountdownSec { public enum CountdownSec {
...@@ -323,9 +343,3 @@ extension Countdown { ...@@ -323,9 +343,3 @@ extension Countdown {
return (Int(day), Int(hour), Int(minute), Int(second)) return (Int(day), Int(hour), Int(minute), Int(second))
} }
} }
extension Int {
public func countup(stop: CountdownSecUpStopBlock?, handler: @escaping CountdownHandler) -> Countdown {
return Countdown().limitCound(self).inSecond(.up(1, stop)).handler(handler)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment