Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-15 13:22:59 +04:00
parent 337b9908c4
commit 292d895c4a
3 changed files with 15 additions and 7 deletions

View file

@ -0,0 +1,30 @@
package com.tangem.data.common.utils
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.yield
import timber.log.Timber
import kotlin.coroutines.cancellation.CancellationException
@Suppress("UnconditionalJumpStatementInLoop")
suspend fun <T> retryOnError(priority: Boolean = false, call: suspend () -> T): T {
while (true) {
return try {
call()
} catch (e: Exception) {
if (e is CancellationException) {
currentCoroutineContext().ensureActive()
}
Timber.e(e, "Error occurred during retryOnError block")
if (priority.not()) {
yield()
delay(timeMillis = 500)
}
continue
}
}
}