Functions to create and execute rate limiters.
Functions to create and execute rate limiters.
(change-limit-for-period! rate-limiter limit-for-period)
Changes the number of allowable calls during a refresh period.
The new limit will take effect in the next refresh period. The current period is not affected.
Changes the number of allowable calls during a refresh period. The new limit will take effect in the next refresh period. The current period is not affected.
(change-timeout-duration! rate-limiter timeout-duration)
Changes the timeout duration milliseconds for the rate limiter.
The new timeout duration will not affect calls currently waiting for permission to execute.
Changes the timeout duration milliseconds for the rate limiter. The new timeout duration will not affect calls currently waiting for permission to execute.
(configure-registry! configs-map)
Overwrites the global registry with one that contains the configs-map.
configs-map is a map whose keys are names and vals are configs. When a rate limiter is created, you may specify one of the names in this map to use as the config for that rate limiter.
:default is a special name. It will be used as the config for rate limiters that do not specify a config to use.
Overwrites the global registry with one that contains the configs-map. configs-map is a map whose keys are names and vals are configs. When a rate limiter is created, you may specify one of the names in this map to use as the config for that rate limiter. :default is a special name. It will be used as the config for rate limiters that do not specify a config to use.
(execute rate-limiter f & args)
Apply args to f within a context protected by the rate limiter.
The function will wait up to the configured timeout duration if the rate limit has been exceeded. If the function is not allowed to execute before the timeout duration expires, this function will throw an exception.
Apply args to f within a context protected by the rate limiter. The function will wait up to the configured timeout duration if the rate limit has been exceeded. If the function is not allowed to execute before the timeout duration expires, this function will throw an exception.
(name rate-limiter)
Gets the name of the rate limiter.
Gets the name of the rate limiter.
(rate-limiter name config)
Creates a rate limiter with the specified name and config.
Creates a rate limiter with the specified name and config.
(rate-limiter! name)
(rate-limiter! name config)
Creates or fetches a rate limiter with the specified name and config and stores it in the global registry.
The config value can be either a config map or the name of a config map stored in the global registry.
If the rate limiter already exists in the global registry, the config value is ignored.
Creates or fetches a rate limiter with the specified name and config and stores it in the global registry. The config value can be either a config map or the name of a config map stored in the global registry. If the rate limiter already exists in the global registry, the config value is ignored.
The global rate limiter and config registry.
The global rate limiter and config registry.
(with-rate-limiter rate-limiter & body)
Executes body within a context protected by the rate limiter.
rate-limiter
is either a rate limiter or the name of one in the global
registry. If you provide a name and a rate limiter of that name does not
already exist in the global registry, one will be created with the :default
config.
The code in body
will wait up to the configured timeout duration if the rate
limit has been exceeded. If the function is not allowed to execute before the
timeout duration expires, an exception will be thrown.
Executes body within a context protected by the rate limiter. `rate-limiter` is either a rate limiter or the name of one in the global registry. If you provide a name and a rate limiter of that name does not already exist in the global registry, one will be created with the `:default` config. The code in `body` will wait up to the configured timeout duration if the rate limit has been exceeded. If the function is not allowed to execute before the timeout duration expires, an exception will be thrown.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close