anchor.diff:      end.
   
   loop_receive_result(
  -  Parent, Debug, #{state := State} = S, Hibernate, Event) ->
  +  Parent, Debug,
  +  #{state := State,
  +    timer_types := TimerTypes, cancel_timers := CancelTimers} = S,
  +  Hibernate, Event) ->
       %% From now the 'hibernate' field in S is invalid
       %% and will be restored when looping back
       %% in loop_event_result/11
       NewDebug = sys_debug(Debug, S, State, {in,Event}),
       %% Here is the queue of not yet handled events created
       Events = [],
  -    loop_event(Parent, NewDebug, S, Events, Event, Hibernate).
  +    %% Cancel any running event timer
  +    case
  +	cancel_timer_by_type(timeout, TimerTypes, CancelTimers)
  +    of
  +	{_,CancelTimers} ->
  +	    %% No timer cancelled
  +	    loop_event(Parent, NewDebug, S, Events, Event, Hibernate);
  +	{NewTimerTypes,NewCancelTimers} ->
  +	    %% The timer is removed from NewTimerTypes but
  +	    %% remains in TimerRefs until we get
  +	    %% the cancel_timer msg
  +	    NewS =
  +		S#{
  +		  timer_types := NewTimerTypes,
  +		  cancel_timers := NewCancelTimers},
  +	    loop_event(Parent, NewDebug, NewS, Events, Event, Hibernate)
  +    end.
   
   %% Entry point for handling an event, received or enqueued
   loop_event(
     Parent, Debug,
  -  #{state := State, data := Data, timer_types := TimerTypes,
  -    cancel_timers := CancelTimers} = S_0,
  +  #{state := State, data := Data} = S,
     Events, {Type,Content} = Event, Hibernate) ->
       %%
       %% If (this old) Hibernate is true here it can only be
  
positive.code:     %% would have happened if we actually hibernated
      %% and immediately was awakened
      Hibernate andalso garbage_collect(),
      case call_state_function(S_0, Type, Content, State, Data) of
  	{ok,Result,S_1} ->
  	    %% Cancel event timeout
  	    S_2 =
  		case
  		    cancel_timer_by_type(timeout, TimerTypes, CancelTimers)
  		of
  		    {_,CancelTimers} ->
  			%% No timer cancelled
  			S_1;
  		    {NewTimerTypes,NewCancelTimers} ->
  			%% The timer is removed from NewTimerTypes but
  			%% remains in TimerRefs until we get
  			%% the cancel_timer msg
  			S_1#{
  			  timer_types := NewTimerTypes,
  			  cancel_timers := NewCancelTimers}
  		end,
  	    {NextState,NewData,Actions,EnterCall} =
  		parse_event_result(
  		  true, Debug, S_2,
  		  Events, Event, State, Data, Result),
  	    loop_event_actions(
  	      Parent, Debug, S_2,
  	      Events, Event, NextState, NewData, Actions, EnterCall);
  	{Class,Reason,Stacktrace} ->
  	    terminate(
  	      Class, Reason, Stacktrace, Debug, S_0,
  	      [Event|Events])
      end.
  
  
negative.code: 	     ?STACKTRACE()}
      end.
  
  %% Stop and start timers as well as create timeout zero events
  %% and pending event timer
  %%
  