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 Detail

      • rateLimitFor

        Mono<Void> rateLimitFor​(Duration duration)
        Sets a new rate limit that will be applied to every operation performed using withLimiter(Publisher).
        Parameters:
        duration - the Duration every new operation should wait before being used
      • getRemaining

        Mono<Duration> getRemaining()
        Returns the Duration remaining 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 Duration indicating the remaining time a global rate limit is being applied. Zero or negative if no global rate limit is currently active.
      • withLimiter

        <T> Flux<T> withLimiter​(Publisher<T> stage)
        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.
        Type Parameters:
        T - the type of the stage supplier
        Parameters:
        stage - a Publisher that will manage this global rate limiter resources
        Returns:
        a Flux where each subscription represents acquiring a rate limiter resource