Swiftpack.co - manuelCarlos/RateLimiters as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by manuelCarlos.
manuelCarlos/RateLimiters 0.0.2
Debounce and Throttle Swift implementations.
⭐️ 2
🕓 1 week ago
iOS
.package(url: "https://github.com/manuelCarlos/RateLimiters.git", from: "0.0.2")

License: MIT

RateLimiters

This package contains two products:

  • Throttler - is a Swift actor that allows the clients to submit work that will only be executed at most once during a given window of time.

  • Debouncer - is a Swift actor that allows clients to submit work that will only be executed if/when no submissions are done during a specified time interval.

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

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

Installation

Adding any of the RateLimiters modules as a Dependency using SPM.

To use these objects in a SwiftPM project, add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/manuelCarlos/RateLimiters.git")
To include only Throttler as a dependency for your executable target:
.target(name: "<target>", dependencies: [
        .product(name: "Throttler", package: "RateLimiters")
]),
To include only Debouncer as a dependency for your executable target:
.target(name: "<target>", dependencies: [
        .product(name: "Debouncer", package: "RateLimiters")
]),

GitHub

link
Stars: 2
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Add documentation on usage and installation.
1 week ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics