RateLimiters
Swift implementation of Debouncing and Throttling actors.
This package contains two user-facing modules:
-
Debouncer- allows submitting work that will only be executed if/when no other submissions occur during a specified time interval. -
Throttler- allows submitting work that will only be executed at most once during a given time window.
Debouncer Usage:
import Debouncer
let debouncer = Debouncer(duration: .seconds(2), clock: .suspending)
func some(operation: @escaping () async -> Void) async {
// The operations submitted here will be debounced by 2 secs.
await debouncer.submit(operation: operation)
}
Throttler Usage:
import Throttler
let throttler = Throttler(duration: .seconds(2), latest: false, clock: .suspending)
func some(operation: @escaping () async -> Void) async {
// The operations submitted here will be throttled by 2 secs.
await throttler.submit(operation: operation)
}
Installation
- Using SPM:
Add the following line to the dependencies in your Package.swift file:
.package(url: "https://github.com/manuelCarlos/RateLimiters.git")
More specifically:
To include only Debouncer:
.target(name: "<target>", dependencies: [
.product(name: "Debouncer", package: "RateLimiters")
]),
To include only Throttler:
.target(name: "<target>", dependencies: [
.product(name: "Throttler", package: "RateLimiters")
]),
On this page
Languages
Swift100.0%
Contributors
MIT License
Created January 2, 2022
Updated November 1, 2025