private long calculateDelay()

in rx-central-ble/src/main/java/com/uber/rxcentralble/core/scanners/ThrottledLollipopScanner.java [187:203]


  private long calculateDelay() {
    long currentTime = System.currentTimeMillis();

    // Remove all timestamps from the queue that are outside the 30 second scan window.
    while ((scanTimestamps.peek() != null)
            && (currentTime - scanTimestamps.peek() > SCAN_WINDOW_MS)) {
      scanTimestamps.remove();
    }

    // If we have 4 timestamps inside the 30 second scan window, return a delay such that
    // the the next scan would occur outisde that 30 second window.
    if (scanTimestamps.size() == 4) {
      return SCAN_WINDOW_MS - (currentTime -  scanTimestamps.peek());
    } else {
      return 0;
    }
  }