Make an asynchronous funcion retryable

async_retryable(task, times)

Arguments

task

An asynchronous function.

times

Number of tries.

Value

Asynchronous retryable function.

Examples

httpbin <- webfakes::new_app_process(webfakes::httpbin_app())
## Create a downloader that retries five times
http_get_5 <- async_retryable(http_get, times = 5)
ret <- synchronise(
  http_get_5(httpbin$url("/get?q=1"))$
    then(function(x) rawToChar(x$content))
)
cat(ret)
#> {
#>   "args": {
#>     "q": "1"
#>   },
#>   "headers": {
#>     "Host": "127.0.0.1:42065",
#>     "User-Agent": "R/4.6.1 R (4.6.1 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions",
#>     "Accept": "*/*",
#>     "Accept-Encoding": "deflate, gzip, br, zstd"
#>   },
#>   "origin": "127.0.0.1",
#>   "path": "/get",
#>   "url": "http://127.0.0.1:42065/get"
#> }