Package discord4j.rest.request
Interface GlobalRateLimiter
- All Known Implementing Classes:
BucketGlobalRateLimiter
public interface GlobalRateLimiter
Used to prevent requests from being sent while the bot is
globally rate limited.
Provides resources that can be acquired through the use of withLimiter(Publisher), and held until the
supplied stage completes or terminates with an error. If the limiter resources are exhausted, it will limit all
other attempts, waiting until a resource becomes available.
This rate limiter can have their delay directly modified through rateLimitFor(Duration), determining the
duration a resource holder must wait before processing starts.
-
Method Summary
Modifier and TypeMethodDescriptionstatic GlobalRateLimitercreate()Create a default limiter based offBucketGlobalRateLimiterthat can be shared across multipleRestClientfor coordinated global rate limit actions.Returns theDurationremaining until the current global rate limit is completed.rateLimitFor(Duration duration) Sets a new rate limit that will be applied to every operation performed usingwithLimiter(Publisher).<T> Flux<T>withLimiter(Publisher<T> stage) Provides a scope to perform reactive operations under this global rate limiter.
-
Method Details
-
create
Create a default limiter based offBucketGlobalRateLimiterthat can be shared across multipleRestClientfor coordinated global rate limit actions.- Returns:
- a default
GlobalRateLimiter
-
rateLimitFor
Sets a new rate limit that will be applied to every operation performed usingwithLimiter(Publisher).- Parameters:
duration- theDurationevery new operation should wait before being used
-
getRemaining
Returns theDurationremaining until the current global rate limit is completed. Can be negative or zero if there is no currently active global rate limit.- Returns:
- a positive
Durationindicating the remaining time a global rate limit is being applied. Zero or negative if no global rate limit is currently active.
-
withLimiter
Provides a scope to perform reactive operations under this global rate limiter. Limiter resources are acquired on subscription and released when the given stage is cancelled, has completed or has been terminated with an error.
-