@Override
    protected void channelRead0(final ChannelHandlerContext channelHandlerContext, final ResponseMessage response) {
        final HttpResponseStatus statusCode = response.getStatus() == null ? null : response.getStatus().getCode();
        final ResultQueue queue = pending.get();

        if ((null == statusCode) || (statusCode == HttpResponseStatus.OK)) {
            final List<Object> data = response.getResult().getData();
            final boolean bulked = channelHandlerContext.channel().attr(HttpGremlinResponseStreamDecoder.IS_BULKED).get();
            // unrolls the collection into individual results to be handled by the queue.
            if (bulked) {
                for (Iterator<Object> iter = data.iterator(); iter.hasNext(); ) {
                    final Object obj = iter.next();
                    final long bulk = (long) iter.next();
                    DefaultRemoteTraverser<Object> item = new DefaultRemoteTraverser<>(obj, bulk);
                    queue.add(new Result(item));
                }
            } else {
                data.forEach(item -> queue.add(new Result(item)));
            }

        } else {
            // this is a "success" but represents no results otherwise it is an error
            if (statusCode != HttpResponseStatus.NO_CONTENT) {
                // Save the error because there could be a subsequent HttpContent coming (probably just trailers). All
                // content should be read first before marking the queue or else this channel might get reused too early.
                channelHandlerContext.channel().attr(CAUGHT_EXCEPTION).set(
                        new ResponseException(response.getStatus().getCode(), response.getStatus().getMessage(),
                                response.getStatus().getException())
                );
            }
        }

        // Stream is done when the last content signaling response message is read.
        if (LAST_CONTENT_READ_RESPONSE == response) {
            final ResultQueue resultQueue = pending.getAndSet(null);
            if (resultQueue != null) {
                if (null == channelHandlerContext.channel().attr(CAUGHT_EXCEPTION).get()) {
                    resultQueue.markComplete();
                } else {
                    resultQueue.markError(channelHandlerContext.channel().attr(CAUGHT_EXCEPTION).getAndSet(null));
                }
            }
        }
    }
Takes a map of requests pending responses and writes responses to the {@link ResultQueue} of a request
as the {@link ResponseMessage} objects are deserialized.
gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/handler/GremlinResponseHandler.java