Retry
When a function may succeed after some attempts, you might need a retry logic - keep trying the function until it succeeds, or after a certain number of attempts. You want some kind of waiting period between each attempt, eg to wait for a network connection.
This can be achieved using Flow.retryFunction .
In the example, we will try up to five times to run the async function doSomething
, starting with 1 second delay if it fails. This time gets longer and longer with each attempt.
See also:
- Flow.waitFor - call a function and be notified if it doesn’t finish within a certain time
Advanced
Options :
taskValueFallback
: option can provide a value if the task ultimately failsabort
: an abort signal to cancel waitingpredelayMs
: time to wait before first attemptlimitAttempts
: total number of times to retrylimitValue
: limit for how many milliseconds to waitstartAt
: starting milliseconds