ThrottleState.make constructor

ThrottleState.make(int quota, ThrottleData data, Duration interval)

Implementation

factory ThrottleState.make(int quota, ThrottleData data, Duration interval) {
  if (data == null) {
    return new ThrottleState(quota, quota, interval.inSeconds, -1);
  }

  int remaining = max(0, quota - data.count);
  int resetsIn = max(0, data.time().difference(new DateTime.now()).inSeconds);
  int retryAfter = -1;
  if (quota <= data.count) {
    retryAfter = max(0,
        data.time().add(interval).difference(new DateTime.now()).inSeconds);
  }
  return new ThrottleState(quota, remaining, resetsIn, retryAfter);
}