Skip to content

Commit

Permalink
feat(latte): remove semaphore wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ShindouMihou committed Aug 5, 2024
1 parent c1cace4 commit 3235145
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions latte/src/main/java/gg/beemo/latte/util/SuspendingRatelimit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ class SuspendingRatelimit(private val burst: Int, private val duration: Duration
}
}

suspend fun tryRequestQuota(): Pair<Boolean, Long?> =
quotaRequestSem.withPermit {
if (remainingQuota <= 0) {
val waitTime = calculateWaitTime()
return@withPermit false to waitTime
}
tryResetQuota()

check(remainingQuota > 0)
remainingQuota--
return@withPermit true to null
fun tryRequestQuota(): Pair<Boolean, Long?> {
if (remainingQuota <= 0) {
val waitTime = calculateWaitTime()
return false to waitTime
}
tryResetQuota()

check(remainingQuota > 0)
remainingQuota--
return true to null
}
}

0 comments on commit 3235145

Please sign in to comment.