anchor.diff:      receive
           {'DOWN', MRef, _, _, _} ->
               %% parent exited there is no need to continue
  +            maybe_close(State),
               exit(normal);
           {Ref, stream_next} ->
               loop(State);
  
positive.code:     receive
          {'DOWN', MRef, _, _, _} ->
              %% parent exited there is no need to continue
              exit(normal);
          {Ref, cancel} ->
              maybe_close(State),
  
negative.code:     loop(State).
  
  -spec system_terminate(any(), _, _, _) -> no_return().
  system_terminate(Reason, _, _, #state{ref=StreamRef,
                                        client_ref=ClientRef}) ->
      hackney:close(ClientRef),
      %% unregister the stream
      catch ets:delete(couchbeam_view_streams, StreamRef),
      exit(Reason).
  