Replace else-if with elif.
This commit is contained in:
parent
1d0f96a966
commit
9b8b0b6339
1 changed files with 9 additions and 8 deletions
|
@ -52,15 +52,16 @@ class Ratelimiter:
|
||||||
if self.balance >= cost:
|
if self.balance >= cost:
|
||||||
self.balance -= cost
|
self.balance -= cost
|
||||||
successful = True
|
successful = True
|
||||||
|
|
||||||
|
elif self.mode == 'reject':
|
||||||
|
successful = False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if self.mode == 'reject':
|
deficit = cost - self.balance
|
||||||
successful = False
|
time_needed = deficit / self.gain_rate
|
||||||
else:
|
time.sleep(time_needed)
|
||||||
deficit = cost - self.balance
|
self.balance = 0
|
||||||
time_needed = deficit / self.gain_rate
|
successful = True
|
||||||
time.sleep(time_needed)
|
|
||||||
self.balance = 0
|
|
||||||
successful = True
|
|
||||||
|
|
||||||
self.last_operation = time.time()
|
self.last_operation = time.time()
|
||||||
return successful
|
return successful
|
||||||
|
|
Loading…
Reference in a new issue