{"id":20918035,"url":"https://github.com/nuclearace/swiftratelimiter","last_synced_at":"2025-05-13T12:31:09.122Z","repository":{"id":23371058,"uuid":"26732384","full_name":"nuclearace/SwiftRateLimiter","owner":"nuclearace","description":"Token Bucket based rate limiter","archived":false,"fork":false,"pushed_at":"2019-12-01T15:42:12.000Z","size":15,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-08-06T02:20:04.064Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nuclearace.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-16T23:46:38.000Z","updated_at":"2023-08-06T02:20:04.065Z","dependencies_parsed_at":"2022-08-05T22:16:07.287Z","dependency_job_id":null,"html_url":"https://github.com/nuclearace/SwiftRateLimiter","commit_stats":null,"previous_names":[],"tags_count":5,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuclearace%2FSwiftRateLimiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuclearace%2FSwiftRateLimiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuclearace%2FSwiftRateLimiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuclearace%2FSwiftRateLimiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuclearace","download_url":"https://codeload.github.com/nuclearace/SwiftRateLimiter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225208996,"owners_count":17438214,"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","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":[],"created_at":"2024-11-18T16:36:59.845Z","updated_at":"2024-11-18T16:37:00.479Z","avatar_url":"https://github.com/nuclearace.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"SwiftRateLimiter\n================\n\nToken Bucket based rate limiter\n\nUse removeTokens to queue rate limited functions.\n\nIf there are not enough tokens in the bucket to fulfill the request, it will dispatch the callback when there are enough. Alternatively, if you create the rate limiter with the optional parameter `firesImmediatly` eg. `let rl = RateLimiter(tokensPerInterval: 10, interval: \"second\", firesImmediatly: true)` it will instead execute callbacks immediately.\n\n```swift\nlet rl = RateLimiter(tokensPerInterval: 10, interval: .second)\n\n// Using trailing closures\nrl.removeTokens(5) {err, tokensRemaining in\n    println(\"Should do first rate limit\")\n    println(tokensRemaining!)\n}\n\n// Callback will execute after 1 seconds\nrl.removeTokens(9) {err, tokensRemaining in\n    println(\"Should do second rate limit\")\n    println(tokensRemaining!)\n}\n\n// Error, requesting more tokens than the bucket can contain\nrl.removeTokens(11) {err, tokensRemaining in\n    println(err)\n}\n\n// A token bucket\nlet tb = TokenBucket(sizeOfBucket: 10, tokensPerInterval: 1, interval: .second)\n\ntb.removeToken(10) {err, tokensRemaining in\n    println(tokensRemaining)\n}\n\n// Bucket is drained\n// Callback will execute after 2 seconds seconds\ntb.removeToken(2) {err, tokensRemaining in\n    println(tokensRemaining)\n}\n\n// Callback will execute after 12 seconds seconds\ntb.removeToken(10) {err, tokensRemaining in\n    println(tokensRemaining!)\n}\n```\n\nTo install just copy the SwiftRateLimiter folder to your project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuclearace%2Fswiftratelimiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuclearace%2Fswiftratelimiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuclearace%2Fswiftratelimiter/lists"}