presto-main/src/main/java/io/prestosql/execution/buffer/LazyOutputBuffer.java/LazyOutputBuffer/destroy
class LazyOutputBuffer:    @Override
    public void destroy()
    {
        OutputBuffer outputBuffer;
        List<PendingRead> pendingReads = ImmutableList.of();
        synchronized (this) {
            if (delegate == null) {
                // ignore destroy if the buffer already in a terminal state.
                if (!state.setIf(FINISHED, state -> !state.isTerminal())) {
                    return;
                }

                pendingReads = ImmutableList.copyOf(this.pendingReads);
                this.pendingReads.clear();
            }
            outputBuffer = delegate;
        }

        // if there is no output buffer, free the pending reads
        if (outputBuffer == null) {
            for (PendingRead pendingRead : pendingReads) {
                pendingRead.getFutureResult().set(emptyResults(taskInstanceId, 0, true));
            }
            return;
        }

        outputBuffer.destroy();
    }