mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-29 21:48:43 +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 {
|
override suspend fun <T> limit(block: suspend () -> T): T {
|
||||||
while (true) {
|
while (true) {
|
||||||
lockState.first { !it }
|
lockState.first { !it }
|
||||||
|
var throwable: Throwable? = null
|
||||||
val result = safely({
|
val result = safely({
|
||||||
when (it) {
|
throwable = when (it) {
|
||||||
is TooMuchRequestsException -> {
|
is TooMuchRequestsException -> {
|
||||||
lock(it.retryAfter.leftToRetry)
|
lock(it.retryAfter.leftToRetry)
|
||||||
Result.failure(it)
|
it
|
||||||
}
|
}
|
||||||
is ClientRequestException -> {
|
is ClientRequestException -> {
|
||||||
if (it.response.status == HttpStatusCode.TooManyRequests) {
|
if (it.response.status == HttpStatusCode.TooManyRequests) {
|
||||||
@ -49,15 +50,16 @@ class ExceptionsOnlyLimiter(
|
|||||||
} else {
|
} else {
|
||||||
throw it
|
throw it
|
||||||
}
|
}
|
||||||
Result.failure(it)
|
it
|
||||||
}
|
}
|
||||||
else -> throw it
|
else -> throw it
|
||||||
}
|
}
|
||||||
|
null
|
||||||
}) {
|
}) {
|
||||||
Result.success(block())
|
block()
|
||||||
}
|
}
|
||||||
if (result.isSuccess) {
|
if (throwable == null) {
|
||||||
return result.getOrNull()!!
|
return result!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user