code: private long nanosToWaitForPermission(final long cyclePeriodInNanos, final int permissionsPerCycle,
                                            final int availablePermissions, final long currentNanos, final long currentCycle) {
          if (availablePermissions > 0) {
              return 0L;
          }
          long nextCycleTimeInNanos = (currentCycle + 1) * cyclePeriodInNanos;
          long nanosToNextCycle = nextCycleTimeInNanos - currentNanos;
          int fullCyclesToWait = (-availablePermissions) / permissionsPerCycle;
          return (fullCyclesToWait * cyclePeriodInNanos) + nanosToNextCycle;
      }
docs: Calculates time to wait for next permission as
  [time to the next cycle] + [duration of full cycles until reserved permissions expire]
  
  @param cyclePeriodInNanos   current configuration values
  @param permissionsPerCycle  current configuration values
  @param availablePermissions currently available permissions, can be negative if some permissions have been reserved
  @param currentNanos         current time in nanoseconds
  @param currentCycle         current {@link AtomicRateLimiter} cycle    @return nanoseconds to wait for the next permission