Improve token management logic

This commit is contained in:
Zed
2021-12-20 04:19:11 +01:00
parent 7af71ec480
commit 5b185c79de
2 changed files with 3 additions and 7 deletions

View File

@@ -57,7 +57,7 @@ template expired(token: Token): untyped =
token.lastUse < time - maxLastUse
template isLimited(token: Token): untyped =
token == nil or (token.remaining <= 1 and token.reset > getTime()) or
token == nil or (token.remaining <= 5 and token.reset > getTime()) or
token.expired
proc release*(token: Token; invalid=false) =
@@ -79,8 +79,6 @@ proc getToken*(): Future[Token] {.async.} =
if result == nil:
raise rateLimitError()
dec result.remaining
proc poolTokens*(amount: int) {.async.} =
var futs: seq[Future[Token]]
for i in 0 ..< amount: