Giter VIP home page Giter VIP logo

gatling's Introduction

Gatling: timer library written in Swift

Gatling

[CI Status](https://travis-ci.org/Louis Zhu/Gatling) Language Version License Platform

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.

Features

  • Unlimited timers working at same time
  • Timers works at any dispatch queue as you wish
  • Each timer has its own interval, working queue, and other configurations
  • Use closure to report timer firing event
  • Stop and release a timer automatically if the caller was no longer exist

More features under developing

  • Pause/resume timers
  • Report more details to caller when a timer fired, such as how many times it has fired, the time interval from its start time, etc
  • Swift 3 supporting
  • Carthage supporting

How to use

Start a timer (load gatling)

Gatling.loadWithTarget(self, timeInterval: 2.0)

The timer firing (gatling shooting) event

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")
    }
    
}

Configure the timer

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"]
        }

Callback closure

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.

About the precision

Gatling is designed to be a easy way to use multiple timers for most cocoa developers. So it is NOT a high precision timer.

  • High precision in not needed for regular usage of timers, such as scroll the paged-advertisement-banner periodically, or fetch new data in background periodically.
  • High precision timers consume compute cycles and battery.

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

Installation

Gatling is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Gatling"

Author

Louis Zhu, [email protected]

License

Gatling is available under the MIT license. See the LICENSE file for more info.

gatling's People

Contributors

louiszhu avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.