Class NewBucketGlobalRateLimiter
java.lang.Object
com.github.alex1304.ultimategdbot.api.NewBucketGlobalRateLimiter
- All Implemented Interfaces:
discord4j.rest.request.GlobalRateLimiter
public class NewBucketGlobalRateLimiter extends Object implements discord4j.rest.request.GlobalRateLimiter
An implementation of
GlobalRateLimiter
that uses a NewRateLimitOperator
coordinate requests, injecting
an additional delay if a source trips the limiter early through rateLimitFor(Duration)
.-
Method Summary
Modifier and Type Method Description static NewBucketGlobalRateLimiter
create()
Creates a new global rate limiter of 50 requests per second usingSchedulers.parallel()
to inject delays.static NewBucketGlobalRateLimiter
create(int capacity, Duration refillPeriod, reactor.core.scheduler.Scheduler delayScheduler)
Creates a new global rate limiter with the given parameters.reactor.core.publisher.Mono<Duration>
getRemaining()
reactor.core.publisher.Mono<Void>
rateLimitFor(Duration duration)
<T> reactor.core.publisher.Flux<T>
withLimiter(org.reactivestreams.Publisher<T> stage)
-
Method Details
-
create
Creates a new global rate limiter of 50 requests per second usingSchedulers.parallel()
to inject delays.- Returns:
- a
NewBucketGlobalRateLimiter
with default parameters
-
create
public static NewBucketGlobalRateLimiter create(int capacity, Duration refillPeriod, reactor.core.scheduler.Scheduler delayScheduler)Creates a new global rate limiter with the given parameters. Be aware that modifying these parameters can lead your bot hitting 429 TOO MANY REQUESTS errors.- Parameters:
capacity
- the number of requests that can be performed in the givenrefillPeriod
refillPeriod
- theDuration
before refilling request permitsdelayScheduler
- theScheduler
used to inject delays- Returns:
- a
NewBucketGlobalRateLimiter
with the given parameters.
-
rateLimitFor
- Specified by:
rateLimitFor
in interfacediscord4j.rest.request.GlobalRateLimiter
-
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
-