zcash-android-wallet-sdk / cash.z.wallet.sdk.ext / retryUpTo

retryUpTo

suspend inline fun retryUpTo(retries: Int, exceptionWrapper: (Throwable) -> Throwable = { it }, initialDelayMillis: Long = 500L, block: (Int) -> Unit): Unit

Execute the given block and if it fails, retry up to retries more times. If none of the retries succeed then throw the final error, which can be wrapped in order to add more context.

Parameters

retries - the number of times to retry the block after the first attempt fails.

exceptionWrapper - a function that can wrap the final failure to add more useful information or context. Default behavior is to just return the final exception.

initialDelayMillis - the initial amount of time to wait before the first retry.

block - the code to execute, which will be wrapped in a try/catch and retried whenever an exception is thrown up to retries attempts.