Similar to base::replicate()
, with some differences:
it takes an async function, instead of an expression, and
it always returns a list.
async_replicate(n, task, ..., .limit = Inf)
Resolves to a list of the results of the n
task
calls.
# \donttest{
## perform an HTTP request three times, and list the reponse times
do <- function() {
async_replicate(3,
function() http_get("https://eu.httpbin.org")$then(function(x) x$times))
}
synchronise(do())
#> [[1]]
#> redirect namelookup connect pretransfer starttransfer
#> 0.000000 0.077127 0.079180 0.104676 0.477593
#> total
#> 0.477742
#>
#> [[2]]
#> redirect namelookup connect pretransfer starttransfer
#> 0.000000 0.000000 0.000000 0.000050 1.672988
#> total
#> 1.782120
#>
#> [[3]]
#> redirect namelookup connect pretransfer starttransfer
#> 0.000000 0.000000 0.000000 0.000020 0.509082
#> total
#> 0.618308
#>
# }