{"id":3018,"url":"https://github.com/soffes/RateLimit","last_synced_at":"2025-08-03T12:31:51.818Z","repository":{"id":62452607,"uuid":"11291042","full_name":"soffes/RateLimit","owner":"soffes","description":"Simple utility for only executing code every so often.","archived":true,"fork":false,"pushed_at":"2019-08-19T18:35:48.000Z","size":123,"stargazers_count":912,"open_issues_count":5,"forks_count":56,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-07-29T08:29:36.439Z","etag":null,"topics":["carthage","ios","macos","swift","tvos","watchos"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soffes.png","metadata":{"files":{"readme":"Readme.markdown","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-09T18:55:17.000Z","updated_at":"2025-03-24T08:47:06.000Z","dependencies_parsed_at":"2022-11-01T22:46:22.667Z","dependency_job_id":null,"html_url":"https://github.com/soffes/RateLimit","commit_stats":null,"previous_names":["soffes/samratelimit"],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/soffes/RateLimit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soffes%2FRateLimit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soffes%2FRateLimit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soffes%2FRateLimit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soffes%2FRateLimit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soffes","download_url":"https://codeload.github.com/soffes/RateLimit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soffes%2FRateLimit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268484362,"owners_count":24257660,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["carthage","ios","macos","swift","tvos","watchos"],"created_at":"2024-01-05T20:16:29.079Z","updated_at":"2025-08-03T12:31:51.530Z","avatar_url":"https://github.com/soffes.png","language":"Swift","readme":"# Rate Limit\n\n[![Version](https://img.shields.io/github/release/soffes/RateLimit.svg)](https://github.com/soffes/RateLimit/releases)\n[![Build Status](https://travis-ci.org/soffes/RateLimit.svg?branch=master)](https://travis-ci.org/soffes/RateLimit)\n![Swift Version](https://img.shields.io/badge/swift-4.0-orange.svg)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![CocoaPods compatible](https://img.shields.io/cocoapods/v/RateLimit.svg)](https://cocoapods.org/pods/RateLimit)\n\nSimple utility for only executing code every so often.\n\nThis 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.\n\nThis is really handy for refreshing stuff in `viewDidAppear:` but preventing it from happening a ton if it was just refreshed.\n\nRate Limit is **fully thread-safe.** Released under the [MIT license](LICENSE).\n\n\n## Usage\n\nWe’ll start out with a `TimedLimiter`:\n\n``` swift\n// Initialize with a limit of 5, so you can only use this once every 5 seconds.\nlet refreshTimeline = TimedLimiter(limit: 5)\n\n// Call the work you want to limit by passing a block to the execute method.\nrefreshTimeline.execute {\n    // Do some work that runs a maximum of once per 5 seconds.\n}\n```\n\nLimiters aren’t persisted across application launches.\n\n### Synchronous Limiters\n\n`TimedLimiter` conforms to the `SyncLimiter` protocol. This means that the block you pass to execute will be called synchronously on the queue you called it from if it should fire. `TimedLimiter` uses time to limit.\n\n`CountedLimiter` is also included. This works by taking a limit as a `UInt` for the maximum number of times to run the block.\n\nThe `SyncLimiter` protocol has a really neat extension that let’s you do things like this:\n\n``` swift\nlet funFactLimiter = CountedLimiter(limit: 2)\nlet funFact = funFactLimiter.execute { () -\u003e String in\n    // Do real things to get a fun fact from a list\n    return \"Hi\"\n}\n```\n\nNow `funFact` is a `String?`. It’s just an optional of whatever you return from the block. The returned value will be `nil` if the block didn’t run.\n\nYou can of course make your own `SyncLimiter`s too!\n\n\n### Asynchronous Limiter\n\nOne `AsyncLimiter` is included. You can make your own too. The included async limiter is `DebouncedLimiter`. This is perfect for making network requests as a user types or other tasks that respond to very frequent events.\n\nThe interface is slightly different:\n\n``` swift\nlet searchLimiter = DebouncedLimiter(limit: 1, block: performSearch)\n\nfunc textDidChange() {\n  searchLimiter.execute()\n}\n```\n\nYou would have to setup the limiter in an initializer since it references an instance method, but you get the idea. The block will be called at most once per second in this configuration.\n\nPretty easy!\n\nOpen up the included [Xcode project](RateLimit.xcodeproj) for an [example app](Example) and [tests](Tests).\n\n\n## Installation\n\n### Carthage\n\n[Carthage](https://github.com/carthage/carthage) is the recommended way to install Rate Limit. Add the following to your Cartfile:\n\n``` ruby\ngithub \"soffes/RateLimit\"\n```\n\n### CocoaPods\n\nAdd the following to your `Podfile`:\n\n``` ruby\npod \"RateLimit\"\n```\n\nThen run `pod install`.\n","funding_links":[],"categories":["Utility","Swift","HarmonyOS"],"sub_categories":["Web View","Other free courses","Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoffes%2FRateLimit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoffes%2FRateLimit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoffes%2FRateLimit/lists"}