Class ClockRateLimiter
java.lang.Object
com.github.alex1304.ultimategdbot.api.ClockRateLimiter
- All Implemented Interfaces:
discord4j.rest.request.GlobalRateLimiter
public class ClockRateLimiter
extends java.lang.Object
implements discord4j.rest.request.GlobalRateLimiter
Custom implementation of GlobalRateLimiter
that uses a clock ticking
at regular intervals in order to give permits for requests.
The effective throughput may be lower than the specified one if Discord's global rate limit is being reached.
- Author:
- Alex1304
-
Constructor Summary
Constructors Constructor Description ClockRateLimiter(int permitsPerTick, java.time.Duration interval)
Creates aClockRateLimiter
with a specified interval and number of permits per tick. -
Method Summary
Modifier and Type Method Description java.time.Duration
getRemaining()
void
rateLimitFor(java.time.Duration duration)
<T> reactor.core.publisher.Flux<T>
withLimiter(org.reactivestreams.Publisher<T> stage)
-
Constructor Details
-
ClockRateLimiter
public ClockRateLimiter(int permitsPerTick, java.time.Duration interval)Creates aClockRateLimiter
with a specified interval and number of permits per tick.- Parameters:
permitsPerTick
- the max number of requests per tickinterval
- the interval between two clock ticks
-
-
Method Details
-
rateLimitFor
public void rateLimitFor(java.time.Duration duration)- Specified by:
rateLimitFor
in interfacediscord4j.rest.request.GlobalRateLimiter
-
getRemaining
public java.time.Duration getRemaining()- Specified by:
getRemaining
in interfacediscord4j.rest.request.GlobalRateLimiter
-
withLimiter
public <T> reactor.core.publisher.Flux<T> withLimiter(org.reactivestreams.Publisher<T> stage)- Specified by:
withLimiter
in interfacediscord4j.rest.request.GlobalRateLimiter
-