code: public final void writeAndRemoveAll(ChannelHandlerContext ctx) {
          decrementReadableBytes(readableBytes);
          Throwable pending = null;
          ByteBuf previousBuf = null;
          for (;;) {
              Object entry = bufAndListenerPairs.poll();
              try {
                  if (entry == null) {
                      if (previousBuf != null) {
                          ctx.write(previousBuf, ctx.voidPromise());
                      }
                      break;
                  }
  
                  if (entry instanceof ByteBuf) {
                      if (previousBuf != null) {
                          ctx.write(previousBuf, ctx.voidPromise());
                      }
                      previousBuf = (ByteBuf) entry;
                  } else if (entry instanceof ChannelPromise) {
                      ctx.write(previousBuf, (ChannelPromise) entry);
                      previousBuf = null;
                  } else {
                      ctx.write(previousBuf).addListener((ChannelFutureListener) entry);
                      previousBuf = null;
                  }
              } catch (Throwable t) {
                  if (pending == null) {
                      pending = t;
                  } else {
                      logger.info("Throwable being suppressed because Throwable {} is already pending", pending, t);
                  }
              }
          }
          if (pending != null) {
              throw new IllegalStateException(pending);
          }
      }
docs: Writes all remaining elements in this queue.
  @param ctx The context to write all elements to.