mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
RequestsExecutor.executeUnsafe(...) retries
This commit is contained in:
parent
05e0ec704e
commit
66be2681c0
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user