async_replicate: Replicate an async function a number of times

View source: R/replicate.R

async_replicateR Documentation

Replicate an async function a number of times

Description

Similar to base::replicate(), with some differences:

  • it takes an async function, instead of an expression, and

  • it always returns a list.

Usage

async_replicate(n, task, ..., .limit = Inf)

Arguments

n

Number of replications.

task

Async function to call.

...

Additional arguments to task.

.limit

Number of concurrent async processes to create.

Value

Resolves to a list of the results of the n task calls.

Examples


## 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())


r-lib/async documentation built on March 24, 2024, 6:20 p.m.