fill changelog and improve RequestQoutaManager API

This commit is contained in:
InsanusMokrassar 2022-12-11 11:17:28 +06:00
parent 9c25b08296
commit cf8ec46513
2 changed files with 20 additions and 8 deletions

View File

@ -2,6 +2,13 @@
## 0.13.0
* Versions:
* `Kotlin`: `1.7.20` -> `1.7.22`
* `Serialization`: `1.4.0` -> `1.4.1`
* `Klock`: `3.2.0` -> `3.4.0`
* `Ktor`: `2.1.2` -> `2.2.1`
* Now it is possible to subscribe onto API limits changes
## 0.12.2
* Versions:

View File

@ -10,6 +10,7 @@ import dev.inmo.saucenaoapi.models.LimitsState
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlin.math.max
@ -18,15 +19,19 @@ import kotlin.math.min
internal class RequestQuotaManager (
scope: CoroutineScope
) {
private val longQuotaFlow = MutableStateFlow(1)
private val shortQuotaFlow = MutableStateFlow(1)
private val longMaxQuotaFlow = MutableStateFlow(1)
private val shortMaxQuotaFlow = MutableStateFlow(1)
private var longQuota by longQuotaFlow::value
private var shortQuota by shortQuotaFlow::value
private var longMaxQuota by longMaxQuotaFlow::value
private var shortMaxQuota by shortMaxQuotaFlow::value
private val _longQuotaFlow = MutableStateFlow(1)
private val _shortQuotaFlow = MutableStateFlow(1)
private val _longMaxQuotaFlow = MutableStateFlow(1)
private val _shortMaxQuotaFlow = MutableStateFlow(1)
private var longQuota by _longQuotaFlow::value
private var shortQuota by _shortQuotaFlow::value
private var longMaxQuota by _longMaxQuotaFlow::value
private var shortMaxQuota by _shortMaxQuotaFlow::value
val longQuotaFlow = _longQuotaFlow.asStateFlow()
val shortQuotaFlow = _shortQuotaFlow.asStateFlow()
val longMaxQuotaFlow = _longMaxQuotaFlow.asStateFlow()
val shortMaxQuotaFlow = _shortMaxQuotaFlow.asStateFlow()
val limitsStateFlow = merge(
longQuotaFlow, shortQuotaFlow, longMaxQuotaFlow, shortMaxQuotaFlow
).map { _ ->