New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add slowly() adverb #389
Comments
I like this idea! library(purrr)
slowly <- function(.f, delay = 1, otherwise, quiet = TRUE) {
.f <- as_mapper(.f)
function(...) {
ret <- purrr:::capture_error(.f(...), otherwise, quiet)
Sys.sleep(delay)
ret
}
}
slow_log <- slowly(log)
timeit <- proc.time()
list(2, 10, 100) %>%
map(slow_log)
#> [[1]]
#> [[1]]$result
#> [1] 0.6931472
#>
#> [[1]]$error
#> NULL
#>
#>
#> [[2]]
#> [[2]]$result
#> [1] 2.302585
#>
#> [[2]]$error
#> NULL
#>
#>
#> [[3]]
#> [[3]]$result
#> [1] 4.60517
#>
#> [[3]]$error
#> NULL
proc.time() - timeit
#> user system elapsed
#> 0.005 0.000 3.012 |
Related: https://github.com/tarakc02/ratelimitr Reprex using library(purrr)
library(ratelimitr)
slow_log <- limit_rate(log, rate(1, 1)) # 1 run / 1 second
system.time({
c(2, 10, 100) %>% map(slow_log)
})
#> User System verstrichen
#> 0.02 0.00 2.09 As you can see, no unnecessary waiting after the last call has been made :) |
Should be made consistent with #333 |
lionel-
added a commit
to lionel-/lowliner
that referenced
this issue
Dec 12, 2018
lionel-
added a commit
to lionel-/lowliner
that referenced
this issue
Dec 20, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recently used
safely()
to wrapgmailr::send_message()
, which I then used withpmap()
to iterate over rows = recipients. I ran into sporadic rate limit problems.It would be nice to also have a
slowly()
adverb for adding a little bit of delay to each call.The text was updated successfully, but these errors were encountered: