Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rate-helpers

Create delaying rate settings


Description

These helpers create rate settings that you can pass to insistently(). You can also use them in your own functions with rate_sleep().

Usage

rate_delay(pause = 1, max_times = Inf)

rate_backoff(
  pause_base = 1,
  pause_cap = 60,
  pause_min = 1,
  max_times = 3,
  jitter = TRUE
)

is_rate(x)

Arguments

pause

Delay between attempts in seconds.

max_times

Maximum number of requests to attempt.

pause_base, pause_cap

rate_backoff() uses an exponential back-off so that each request waits pause_base * 2^i seconds, up to a maximum of pause_cap seconds.

pause_min

Minimum time to wait in the backoff; generally only necessary if you need pauses less than one second (which may not be kind to the server, use with caution!).

jitter

Whether to introduce a random jitter in the waiting time.

x

An object to test.

See Also

Examples

# A delay rate waits the same amount of time:
rate <- rate_delay(0.02)
for (i in 1:3) rate_sleep(rate, quiet = FALSE)

# A backoff rate waits exponentially longer each time, with random
# jitter by default:
rate <- rate_backoff(pause_base = 0.2, pause_min = 0.005)
for (i in 1:3) rate_sleep(rate, quiet = FALSE)

purrr

Functional Programming Tools

v0.3.4
GPL-3 | file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.