TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jul 2016 |
SPMSupports SPM | ✗ |
Maintained by Louis Zhu.
Gatling is an timer library written in Swift which lets you create multiple timers, multithreaded. Every timers has its own interval, working queue, and other configurations.
Gatling.loadWithTarget(self, timeInterval: 2.0)
Normally, Gatling invokes a ‘callback’ method to inform the caller that the timer is firing (the gatling is shooting). You can simply implement the method to receive the event.
extension MyClass: GatlingTarget {
func shotWithBullet(bullet: Bullet?) {
print("Ahhhh, I'm being shot by gatling")
}
}
Beside the simplest timer mentioned above, you can configure your timer for more details. Including
shouldShootImmediately: Bool
: Indicates if the timers should fire immediately. If false
it doesn’t, just acts like the NSTimer
; if true
, the timer will perform an extra firing immediately after the 'loading’ method was invoked.workingQueue: dispatch_queue_t
: In which dispatch queue the callback will execute. Yes gatling is a multithreaded timer so you can specify any queue as you wish.bullet: Bullet?
: The user info for the timer, treat it as userInfo
of NSTimer
. Gatling will pass it back to you in the callback method. Gatling.loadWithTarget(self, timeInterval: 1.5) { (configuration) in
configuration.shouldShootImmediately = true
configuration.workingQueue = dispatch_queue_create("com.mycompany.queue.working", nil)
configuration.bullet = ["Identifier": "some identifier"]
}
You can use a callback closure to receive the timer’s firing event. Specify it in the Configuraion
.
Gatling.loadWithTarget(self, timeInterval: 1.5) { (configuration) in
configuration.onShoot = { bullet in
print("Ahhhh, I'm being shot by gatling")
}
}
NOTE: if you have specified a callback closure the 'callback method’ will not be invoked.
Gatling is designed to be a easy way to use multiple timers for most cocoa developers. So it is NOT a high precision timer.
Gatling uses GCD as the underlying technology. So it’s better to keep the timer’s working queue clean and simple to avoid blocking the queue. The best practice is to use an individual queue for every individual timer.
Gatling uses mach absolute time to offer the highest precision as possible. For more information, please refer https://developer.apple.com/library/mac/qa/qa1398/_index.html
For more information about high precision timers, or you do need a high precision timer, please refer https://developer.apple.com/library/ios/technotes/tn2169/_index.html
Gatling is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Gatling"
Louis Zhu, [email protected]
Gatling is available under the MIT license. See the LICENSE file for more info.