Liking cljdoc? Tell your friends :D

resilience4clj.rate-limiter

Functions to create and execute rate limiters.

Functions to create and execute rate limiters.
raw docstring

acquire-permission!clj

(acquire-permission! rate-limiter)
(acquire-permission! rate-limiter permits)

Attempts to acquire the specified number of permits from rate-limiter.

Blocks until all permits are received or the rate limiter timeout duration is exceeded. Returns a value indicating success.

The default permit value is 1.

Attempts to acquire the specified number of permits from `rate-limiter`.

Blocks until all permits are received or the rate limiter timeout duration is
exceeded. Returns a value indicating success.

The default permit value is 1.
sourceraw docstring

add-configuration!clj

(add-configuration! name config)
(add-configuration! registry name config)

Adds config to the registry under the name.

Uses default-registry if registry is not provided.

Adds `config` to the `registry` under the `name`.

Uses [[default-registry]] if `registry` is not provided.
sourceraw docstring

all-rate-limitersclj

(all-rate-limiters)
(all-rate-limiters registry)

Gets all the rate limiters in registry.

Uses default-registry if registry is not provided.

Gets all the rate limiters in `registry`.

Uses [[default-registry]] if `registry` is not provided.
sourceraw docstring

change-limit-for-period!clj

(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.
sourceraw docstring

change-timeout-duration!clj

(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.
sourceraw docstring

default-registryclj

The global ratelimiter and config registry.

The global ratelimiter and config registry.
sourceraw docstring

drain-permissions!clj

(drain-permissions! rate-limiter)

Drains all the permits left in the current period.

Drains all the permits left in the current period.
sourceraw docstring

emit-events!clj

(emit-events! rate-limiter out-chan & {:keys [only exclude] :or {exclude []}})

Offers events on rate-limiter to out-chan.

The event types are identified by event-types.

This function also accepts :only and :exclude keyword params that are sequences of the event types that should be included or excluded, respectively.

Offers events on `rate-limiter` to `out-chan`.

The event types are identified by [[event-types]].

This function also accepts `:only` and `:exclude` keyword params that are
sequences of the event types that should be included or excluded,
respectively.
sourceraw docstring

emit-registry-events!clj

(emit-registry-events! out-chan)
(emit-registry-events! registry
                       out-chan
                       &
                       {:keys [only exclude] :or {exclude []}})

Offers registry events to out-chan.

The event types are identified by registry-event-types.

This function also accepts :only and :exclude keyword params that are sequences of the event types that should be included or excluded, respectively.

Uses default-registry if registry is not provided.

Offers registry events to `out-chan`.

The event types are identified by [[registry-event-types]].

This function also accepts `:only` and `:exclude` keyword params that are
sequences of the event types that should be included or excluded,
respectively.

Uses [[default-registry]] if `registry` is not provided.
sourceraw docstring

event-typesclj

source

executeclj

(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.
sourceraw docstring

findclj

(find name)
(find registry name)

Finds the rate limiter identified by name in registry.

Uses default-registry if registry is not provided.

Finds the rate limiter identified by `name` in `registry`.

Uses [[default-registry]] if `registry` is not provided.
sourceraw docstring

nameclj

(name rate-limiter)

Gets the name of the rate limiter.

Gets the name of the rate limiter.
sourceraw docstring

rate-limiterclj

(rate-limiter name)
(rate-limiter name config)

Creates a rate limiter with the name and config.

Creates a rate limiter with the `name` and `config`.
sourceraw docstring

rate-limiter!clj

(rate-limiter! name)
(rate-limiter! registry name)
(rate-limiter! registry name config)

Creates or fetches a rate limiter with the specified name and config and stores it in registry.

The config value can be either a config map or the name of a config map stored in the registry. If the rate limiter already exists in the registry, the config value is ignored.

Uses default-registry if registry is not provided.

Creates or fetches a rate limiter with the specified name and config and 
stores it in `registry`.

The config value can be either a config map or the name of a config map stored
in the registry. If the rate limiter already exists in the registry, the 
config value is ignored. 

Uses [[default-registry]] if `registry` is not provided.
sourceraw docstring

registryclj

(registry)
(registry configs-map)

Creates a registry with default values or a map of name/config-map pairs.

Creates a registry with default values or a map of name/config-map pairs.
sourceraw docstring

registry-event-typesclj

The event types that can be raised by a registry.

The event types that can be raised by a registry.
sourceraw docstring

remove!clj

(remove! name)
(remove! registry name)

Removes the rate limiter identified by name from registry.

Uses default-registry if registry is not provided.

Removes the rate limiter identified by `name` from `registry`.

Uses [[default-registry]] if `registry` is not provided.
sourceraw docstring

replace!clj

(replace! name rate-limiter)
(replace! registry name rate-limiter)

Replaces the rate limiter identified by name in registry with the specified rate-limiter.

Uses default-registry if registry is not provided.

Replaces the rate limiter identified by `name` in `registry` with the specified `rate-limiter`.

Uses [[default-registry]] if `registry` is not provided.
sourceraw docstring

reserve-permission!clj

(reserve-permission! rate-limiter)
(reserve-permission! rate-limiter permits)

Reserves the specified number of permits.

Returns the number of nanoseconds you must wait to use the permission. If the number is negative, the request to reserve permission failed. This failure mode may occur if the number of nanoseconds to wait exceeds the rate limiter timeout duration.

The default permit value is 1.

Reserves the specified number of permits.

Returns the number of nanoseconds you must wait to use the permission. If the
number is negative, the request to reserve permission failed. This failure
mode may occur if the number of nanoseconds to wait exceeds the rate limiter
timeout duration.

The default permit value is 1.
sourceraw docstring

with-rate-limitercljmacro

(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.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close