mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
ExceptionsOnlyLimiter now will not use Result to provide success/failure state of result
This commit is contained in:
parent
a2ea15d4b0
commit
4748b6813a
@ -37,11 +37,12 @@ class ExceptionsOnlyLimiter(
|
||||
override suspend fun <T> limit(block: suspend () -> T): T {
|
||||
while (true) {
|
||||
lockState.first { !it }
|
||||
var throwable: Throwable? = null
|
||||
val result = safely({
|
||||
when (it) {
|
||||
throwable = when (it) {
|
||||
is TooMuchRequestsException -> {
|
||||
lock(it.retryAfter.leftToRetry)
|
||||
Result.failure(it)
|
||||
it
|
||||
}
|
||||
is ClientRequestException -> {
|
||||
if (it.response.status == HttpStatusCode.TooManyRequests) {
|
||||
@ -49,15 +50,16 @@ class ExceptionsOnlyLimiter(
|
||||
} else {
|
||||
throw it
|
||||
}
|
||||
Result.failure(it)
|
||||
it
|
||||
}
|
||||
else -> throw it
|
||||
}
|
||||
null
|
||||
}) {
|
||||
Result.success(block())
|
||||
block()
|
||||
}
|
||||
if (result.isSuccess) {
|
||||
return result.getOrNull()!!
|
||||
if (throwable == null) {
|
||||
return result!!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user