code: private CompletableFuture<WriterFlushResult> flushPendingTruncate(WriterFlushResult flushResult, Duration timeout) {
          StorageOperation op = this.operations.getFirst();
          if (!isTruncateOperation(op) || !this.storage.supportsTruncation()) {
              // Nothing to do.
              return CompletableFuture.completedFuture(flushResult);
          }
  
          CompletableFuture<Void> truncateTask;
          if (this.handle.get() == null) {
              // Segment has not been created yet.
              assert this.metadata.getStorageLength() == 0 : "handle is null but Metadata.getStorageLength is non-zero";
              truncateTask = CompletableFuture.completedFuture(null);
          } else {
              long truncateOffset = Math.min(this.metadata.getStorageLength(), op.getStreamSegmentOffset());
              truncateTask = this.storage.truncate(this.handle.get(), truncateOffset, timeout);
          }
  
          return truncateTask.thenApplyAsync(v -> {
              updateStatePostTruncate();
              return flushResult;
          }, this.executor);
      }
docs: Flushes a pending StreamSegmentTruncateOperation, if that is the next pending one.
  
  @param flushResult The FlushResult of the operation just prior to this.
  @param timeout     Timeout for the operation.
  @return A CompletableFuture that, when completed, will contain the result from the flush operation, merged in with
  the one passed in as input.