Skip to content

mz2/MPRateLimiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MPRateLimiter Carthage compatible

A synchronous rate limiter for Swift.

  • The current thread waits for the closure's rate limited execution.
  • Public interface is thread safe.
  • Allows for rethrowing errors thrown by the rate limited executed closure.

If you don't want this behaviour where waiting is done synchronously, and instead need rate limiting of the sort where rate limited execution may be dispatched asynchronously in another call stack, you may want to try something like DORateLimit instead.

Usage examples

let limiter = RateLimiter()

// Executes at the maximum rate of 0.1s since the previously executed closure with matching key "foo"
limiter.execute(key:"foo", rateLimit:0.1) {
  print("bar")
}

About

A synchronous rate limiter for Swift: makes the current thread wait (as opposed to dispatching in the future after throttling rate limit has passed).

Resources

License

Stars

Watchers

Forks

Packages

No packages published