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.
httpbin <- webfakes::new_app_process(
webfakes::httpbin_app(),
opts = webfakes::server_opts(num_threads = 3)
)
## perform an HTTP request three times, and list the reponse times
do <- function() {
async_replicate(3,
function() http_get(httpbin$url("/get"))$then(function(x) x$times))
}
synchronise(do())
#> [[1]]
#> redirect namelookup connect pretransfer starttransfer
#> 0.000000 0.000026 0.001766 0.001816 0.015485
#> total
#> 0.015694
#>
#> [[2]]
#> redirect namelookup connect pretransfer starttransfer
#> 0.000000 0.000008 0.001681 0.001709 0.020255
#> total
#> 0.020327
#>
#> [[3]]
#> redirect namelookup connect pretransfer starttransfer
#> 0.000000 0.000007 0.001663 0.001706 0.018276
#> total
#> 0.018416
#>