Package discord4j.gateway
Interface GatewayLimiter
-
- All Known Implementing Classes:
SimpleBucket
public interface GatewayLimiter
Represents a rate-limiting strategy that can be shared across shards.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description long
delayMillisToConsume(long tokens)
Calculate the time (in milliseconds) a consumer should delay a call totryConsume(int)
in order to be successful.boolean
tryConsume(int numberTokens)
Attempt to consume a given number of permits from this bucket.
-
-
-
Method Detail
-
tryConsume
boolean tryConsume(int numberTokens)
Attempt to consume a given number of permits from this bucket.This method does not block or incur in any waiting step. If no permits are available, this method will simply return
false
. To obtain the delay needed to wait in order to consume the next tokens, seedelayMillisToConsume(long)
.- Parameters:
numberTokens
- the permits to consume- Returns:
true
if it was successful,false
otherwise
-
delayMillisToConsume
long delayMillisToConsume(long tokens)
Calculate the time (in milliseconds) a consumer should delay a call totryConsume(int)
in order to be successful.- Parameters:
tokens
- the number of permits sought to consume- Returns:
- delay in milliseconds that a consumer must wait to consume
tokens
amount of permits.
-
-