anchor.diff:      end.
   
   handle_cast({set_idle_timeout, Timeout}, State) ->
  -    {noreply, refresh_idle_timeout(State#state{idle_timeout = Timeout})};
  +    cancel_idle_timeout(State),
  +    {noreply, start_idle_timeout(State#state{idle_timeout = Timeout})};
   
  -handle_cast(idle_timeout, State) ->
  +handle_cast({idle_timeout, Ref}, State = #state{idle_timeout_ref = Ref}) ->
       {stop, idle_timeout, State};
   
  +handle_cast({idle_timeout, _OtherRef}, State) ->
  +    %% ignore timeouts other than the current one
  +    {noreply, State};
  +
   handle_cast({do_binary_request, JSONRequest}, State = #state{mod = Mod, mod_state = ModState}) ->
  +    cancel_idle_timeout(State),
       case hello_proto:request_json(JSONRequest) of
           {ok, Request} ->
               From = make_from_context(State, Request),
               Result = Mod:handle_request(From, Request#request.method, Request#request.params, ModState),
  -            NewState = refresh_idle_timeout(State),
  +            NewState = start_idle_timeout(State),
               handle_result(Result, true, From, NewState);
           {error, ErrorResponse} ->
               send_binary(make_context(State), ErrorResponse),
  
positive.code: make_from_context(#state{transport_mod = TMod, transport_state = TState}, Request) ->
      #context{transport_mod = TMod, transport_state = TState, request = Request}.
  
  refresh_idle_timeout(State) ->
      case State#state.idle_timer of
          undefined ->
              ok;
          OldTimer ->
              {ok, cancel} = timer:cancel(OldTimer)
      end,
  
      case State#state.idle_timeout of
          infinity ->
              State#state{idle_timer = undefined};
          IdleTimeout ->
              {ok, NewTimer} = timer:apply_after(IdleTimeout, gen_server, cast, [self(), idle_timeout]),
              State#state{idle_timer = NewTimer}
      end.
  
negative.code: 
  %% --------------------------------------------------------------------------------
  %% -- gen_server callbacks
  -record(state, {transport_mod, transport_state, mod, mod_state, idle_timer, idle_timeout_ref, idle_timeout = infinity}).
  
  init({TransportMod, Transport, HandlerModule, Args}) ->
      State0 = #state{mod = HandlerModule, transport_mod = TransportMod, transport_state = Transport},
      State1 = start_idle_timeout(State0),
      case HandlerModule:init(make_context(State1), Args) of
          {ok, HandlerState} ->
              {ok, State1#state{mod_state = HandlerState}};
  