Keeps trying until the function's deferred value resolves without
error, or times
tries have been performed, or time_limit
seconds
have passed since the start of the first try.
async_backoff(
task,
...,
.args = list(),
times = Inf,
time_limit = Inf,
custom_backoff = NULL,
on_progress = NULL,
progress_data = NULL
)
An asynchronous function.
Arguments to pass to task
.
More arguments to pass to task
.
Maximum number of tries.
Maximum number of seconds to try.
If not NULL
then a callback function to
calculate waiting time, after the i
the try. i
is passed as an
argument. If NULL
, then the default is used, which is a uniform
random number of seconds between 1 and 2^i.
Callback function for a progress bar. Retries are
announced here, if not NULL
. on_progress
is called with two
arguments. The first is a named list with entries:
event
: string that is either "retry"
or "givenup"
,
tries
: number of tried so far,
spent
: number of seconds spent trying so far,
error
: the error object for the last failure,
retry_in
: number of seconds before the next try.
The second argument is progress_data
.
async_backoff()
will pass this object to
on_progress
as the second argument.
Deferred value for the operation with retries.
Note that all unnamed arguments are passed to task
.
Other async control flow:
async_reflect()
,
async_retry()
,
async_retryable()
,
async_sequence()
,
async_try_each()
,
async_until()
,
async_whilst()
# \donttest{
afun <- function() {
wait_100_ms <- function(i) 0.1
async_backoff(
function() if (runif(1) < 0.8) stop("nope") else "yes!",
times = 5,
custom_backoff = wait_100_ms
)
}
# There is a slight chance that it fails
tryCatch(synchronise(afun()), error = function(e) e)
#> <async error: nope
#> in *action* callback of `deferred$new` at ?/?:?:?>
# }