1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

RequestsExecutor.executeUnsafe(...) retries

This commit is contained in:
InsanusMokrassar 2019-01-31 09:57:49 +08:00
parent 05e0ec704e
commit 66be2681c0
2 changed files with 10 additions and 2 deletions

View File

@ -25,6 +25,7 @@ must be regular text
### 0.9.2 ### 0.9.2
* `RequestsExecutor#executeAsync(Request, CoroutineScope)` now will return `Deferred` for cases when you need result * `RequestsExecutor#executeAsync(Request, CoroutineScope)` now will return `Deferred` for cases when you need result
* `RequestsExecutor#executeUnsafe` will automatically retry request if it was unsuccessful and retries > 0
### 0.8.5 ### 0.8.5

View File

@ -169,11 +169,18 @@ fun <T: Any> RequestsExecutor.executeAsync(
} }
suspend fun <T: Any> RequestsExecutor.executeUnsafe( suspend fun <T: Any> RequestsExecutor.executeUnsafe(
request: Request<T> request: Request<T>,
retries: Int = 0,
retriesDelay: Long = 1000L
): T? { ): T? {
return try { return try {
execute(request) execute(request)
} catch (e: RequestException) { } catch (e: RequestException) {
null if (retries > 0) {
delay(retriesDelay)
executeUnsafe(request, retries - 1, retriesDelay)
} else {
null
}
} }
} }