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 Details

    • create

      public static NewBucketGlobalRateLimiter create()
      Creates a new global rate limiter of 50 requests per second using Schedulers.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 given refillPeriod
      refillPeriod - the Duration before refilling request permits
      delayScheduler - the Scheduler 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 interface discord4j.rest.request.GlobalRateLimiter
    • getRemaining

      public reactor.core.publisher.Mono<Duration> getRemaining()
      Specified by:
      getRemaining in interface discord4j.rest.request.GlobalRateLimiter
    • withLimiter

      public <T> reactor.core.publisher.Flux<T> withLimiter​(org.reactivestreams.Publisher<T> stage)
      Specified by:
      withLimiter in interface discord4j.rest.request.GlobalRateLimiter