code: synchronized CleanupStatus removeFinishedWrites() {
          Exceptions.checkNotClosed(this.closed, this);
          long currentTime = this.timeSupplier.get();
          long totalElapsed = 0;
          int removedCount = 0;
          boolean failedWrite = false;
          while (!this.writes.isEmpty() && this.writes.peekFirst().isDone()) {
              Write w = this.writes.removeFirst();
              this.totalLength = Math.max(0, this.totalLength - w.data.getLength());
              removedCount++;
              totalElapsed += currentTime - w.getQueueAddedTimestamp();
              failedWrite |= w.getFailureCause() != null;
          }
  
          if (removedCount > 0) {
              this.lastDurationMillis = (int) (totalElapsed / removedCount / AbstractTimer.NANOS_TO_MILLIS);
          }
  
          return failedWrite
                  ? CleanupStatus.WriteFailed
                  : this.writes.isEmpty() ? CleanupStatus.QueueEmpty : CleanupStatus.QueueNotEmpty;
      }
docs: Removes all the completed writes (whether successful or failed) from the beginning of the queue, until the first
  non-completed item is encountered or the queue is empty.
  
  @return A CleanupStatus representing the state of the Operation. If there were failed writes, this will be WriteFailed,
  otherwise it will be one of QueueEmpty or QueueNotEmpty, depending on the final state of the queue when this method
  finishes.