anchor.diff:      end.
   
   % callbacks for continuous feed (newline-delimited JSON Objects)
  -changes_callback(start, {"continuous", Req}) ->
  -    {ok, Resp} = chttpd:start_delayed_json_response(Req, 200),
  -    {ok, {"continuous", Resp}};
  -changes_callback({change, Change}, {"continuous", Resp}) ->
  +changes_callback(start, #cacc{feed = continuous} = Acc) ->
  +    {ok, Resp} = chttpd:start_delayed_json_response(Acc#cacc.mochi, 200),
  +    {ok, Acc#cacc{mochi = Resp, responding = true}};
  +changes_callback({change, Change}, #cacc{feed = continuous} = Acc) ->
  +    #cacc{mochi = Resp} = Acc,
       {ok, Resp1} = chttpd:send_delayed_chunk(Resp, [?JSON_ENCODE(Change) | "\n"]),
  -    {ok, {"continuous", Resp1}};
  -changes_callback({stop, EndSeq0, Pending}, {"continuous", Resp}) ->
  +    {ok, Acc#cacc{mochi = Resp1}};
  +changes_callback({stop, EndSeq0, Pending}, #cacc{feed = continuous} = Acc) ->
  +    #cacc{mochi = Resp} = Acc,
       EndSeq = case is_old_couch(Resp) of true -> 0; false -> EndSeq0 end,
       Row = {[
           {<<"last_seq">>, EndSeq},
  
positive.code:     chttpd:end_delayed_json_response(Resp1);
  
  % callbacks for eventsource feed (newline-delimited eventsource Objects)
  changes_callback(start, {"eventsource", Req}) ->
      Headers = [
          {"Content-Type", "text/event-stream"},
          {"Cache-Control", "no-cache"}
      ],
      {ok, Resp} = chttpd:start_delayed_json_response(Req, 200, Headers),
      {ok, {"eventsource", Resp}};
  changes_callback({change, {ChangeProp}=Change}, {"eventsource", Resp}) ->
      Seq = proplists:get_value(seq, ChangeProp),
      Chunk = [
          "data: ", ?JSON_ENCODE(Change),
  
negative.code:     end,
      chttpd:end_delayed_json_response(Resp1);
  
  changes_callback(timeout, Acc) ->
      {ok, Resp1} = chttpd:send_delayed_chunk(Acc#cacc.mochi, "\n"),
      {ok, Acc#cacc{mochi = Resp1}};
  changes_callback({error, Reason}, #cacc{mochi = #httpd{}} = Acc) ->
      #cacc{mochi = Req} = Acc,
      chttpd:send_error(Req, Reason);
  changes_callback({error, Reason}, #cacc{feed = normal, responding = false} = Acc) ->
      #cacc{mochi = Req} = Acc,
      chttpd:send_error(Req, Reason);
  changes_callback({error, Reason}, Acc) ->
      chttpd:send_delayed_error(Acc#cacc.mochi, Reason).
  
  is_old_couch(Resp) ->
      MochiReq = chttpd:get_delayed_req(Resp),
  