Update ExceptionsOnlyLimiter.kt

This commit is contained in:
InsanusMokrassar 2022-12-27 22:25:26 +06:00 committed by GitHub
parent f686be0271
commit f9a9f958ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 0 additions and 28 deletions

View File

@ -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]
*/