anchor.diff:                    queue = queue:in(Req, Q),
                     async = Async}};
   
  -handle_cast(stop, #state{queue = Q} = State) ->
  -    %% TODO flush queue
  -    {stop, normal, State};
  +handle_cast(stop, State) ->
  +    {stop, normal, flush_queue(State, {error, stop})};
   
   handle_cast(Req = {_, {squery, Sql}}, State) ->
       #state{queue = Q} = State,
  
positive.code:             end;
          true ->
              State#state{sync_required = true}
      end.
  
  to_binary(B) when is_binary(B) -> B;
  
negative.code: 
  handle_info({Closed, Sock}, #state{sock = Sock} = State)
    when Closed == tcp_closed; Closed == ssl_closed ->
      {stop, sock_closed, flush_queue(State, {error, sock_closed})};
  
  handle_info({Error, Sock, Reason}, #state{sock = Sock} = State)
    when Error == tcp_error; Error == ssl_error ->
      Why = {sock_error, Reason},
      {stop, Why, flush_queue(State, {error, Why})};
  
  handle_info({_, Sock, Data2}, #state{data = Data, sock = Sock} = State) ->
      loop(State#state{data = <<Data/binary, Data2/binary>>}).
  