folly::coro::retryWhen

Execute a given asynchronous operation returned by func(), retrying it on failure, if desired, after awaiting retryDelay(error).

Synopsis

Declared in <folly/coro/Retry.h>

template<
    typename Func,
    typename RetryDelayFunc>
Task<semi_await_result_t<invoke_result_t<Func&>>>
retryWhen(
    Func func,
    RetryDelayFunc retryDelay);

Description

If 'func()' operation succeeds or completes with OperationCancelled then completes immediately with that result.

Otherwise, if it fails with an error then the function 'retryDelay()' is invoked with the exception_wrapper for the error and must return another Task<void>.

If this task completes successfully or completes with then it will retry the func() operation, otherwise if it completes with an error then the whole operation will complete with that error.

This allows you to do some asynchronous work between retries (such as sleeping for a given duration, but could be some reparatory work in response to particular errors) and the retry will be scheduled once the retryDelay() operation completes successfully.

Return Value

A task producing the operation's result.

Parameters

NameDescription
funcCallable returning the awaitable operation to run.
retryDelayCallable invoked with each error, returning an awaitable delay before retrying.