jjulian / RateLimit

Simple utility for only executing code every so often.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rate Limit

Version Build Status Carthage compatible CocoaPods compatible

Simple utility for only executing code every so often.

This will only execute the block passed for a given name if the last time it was called is greater than limit or it has never been called.

This is really handy for refreshing stuff in viewDidAppear: but preventing it from happening a ton if it was just refreshed.

Rate Limit is fully thread-safe. Released under the MIT license.

Usage

RateLimit.execute(name: "RefreshTimeline", limit: 60) {
    // Do some work that runs a maximum of once per minute
}

Rate Limit doesn't persist limts across application launches. For most cases, this is ideal. If you need persistence, simply replace RateLimit with PersistentRateLimit for on disk persistence. Easy as that.

Open up the included Xcode project for an example app and tests. See the code for full documentation.

Installation

Simply add the files in the RateLimit directory to your project or add RateLimit to your Podfile if you're using CocoaPods.

About

Simple utility for only executing code every so often.

License:MIT License


Languages

Language:Swift 79.4%Language:Ruby 16.6%Language:Objective-C 4.0%