Description Usage Arguments Value See Also Examples
Limit the rate at which a function will execute
1 2 3 4 5 6 7 8 9 10 | limit_rate(f, ..., precision = 60)
## S3 method for class 'list'
limit_rate(f, ..., precision = 60)
## S3 method for class 'function_list'
limit_rate(f, ..., precision = 60)
## S3 method for class 'function'
limit_rate(f, ..., precision = 60)
|
f |
A single function to be rate-limited, or a named list of functions |
... |
One or more rates, created using |
precision |
The precision with which time intervals can be measured, in hertz |
If f
is a single function, then a new function with the same
signature and (eventual) behavior as the original function, but rate limited.
If f
is a named list of functions, then a new list of functions with the
same names and signatures, but collectively bound by a shared rate limit.
1 2 3 4 5 6 7 8 9 10 11 | ## limiting a single function
f <- limit_rate(Sys.time, rate(n = 5, period = .1))
res <- replicate(10, f())
## show the elapsed time between each function call:
round(res[-1] - head(res, -1), 3)
## for multiple functions, make sure the list is named:
f <- function() 1
g <- function() 2
limited <- limit_rate(list(f = f, g = g), rate(n = 1, period = .1))
system.time({limited$f(); limited$g()})
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.