Throttler
- an actor that allows submitting work that will only be executed at most once during a given window of time.
Debouncer
- an actor that allows submitting work that will only be executed if/when no submissions are done during a specified time interval.
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)
}
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)
}
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")
Throttler
as a dependency for your executable target:.target(name: "<target>", dependencies: [
.product(name: "Throttler", package: "RateLimiters")
]),
Debouncer
as a dependency for your executable target:.target(name: "<target>", dependencies: [
.product(name: "Debouncer", package: "RateLimiters")
]),
link |
Stars: 5 |
Last commit: 1 week ago |
Full Changelog: https://github.com/manuelCarlos/RateLimiters/compare/0.1.0...0.1.1
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics