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 ofGlobalRateLimiter
that uses aNewRateLimitOperator
coordinate requests, injecting an additional delay if a source trips the limiter early throughrateLimitFor(Duration)
.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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 Detail
-
create
public static NewBucketGlobalRateLimiter 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
public reactor.core.publisher.Mono<Void> rateLimitFor(Duration duration)
- Specified by:
rateLimitFor
in interfacediscord4j.rest.request.GlobalRateLimiter
-
getRemaining
public reactor.core.publisher.Mono<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
-
-