mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 19:48:43 +00:00
Update ExceptionsOnlyLimiter.kt
This commit is contained in:
parent
f686be0271
commit
f9a9f958ba
@ -27,34 +27,6 @@ import kotlinx.coroutines.sync.withLock
|
||||
class ExceptionsOnlyLimiter(
|
||||
private val defaultTooManyRequestsDelay: MilliSeconds = 1000L,
|
||||
) : RequestLimiter {
|
||||
/**
|
||||
* Should be used for all [mutexesMap] changes
|
||||
*/
|
||||
private val lockMutex = Mutex()
|
||||
|
||||
/**
|
||||
* Contains [Mutex]es for [Any] keys. If [Mutex] is presented it means that [lock] function has been called and
|
||||
* that mutex should be locked for some time
|
||||
*/
|
||||
private val mutexesMap = mutableMapOf<Any, Mutex>()
|
||||
private suspend fun lock(
|
||||
key: Any,
|
||||
timeMillis: MilliSeconds
|
||||
) {
|
||||
val mutex = Mutex()
|
||||
mutex.withLock {
|
||||
safely {
|
||||
lockMutex.withLock {
|
||||
mutexesMap[key] = mutex
|
||||
}
|
||||
delay(timeMillis)
|
||||
lockMutex.withLock {
|
||||
mutexesMap.remove(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Just call [block]
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user