anchor.diff:  
   merge_state(#state{interval = I, delay_between_executions = D, n = N, max_n = MaxN},
               #state{n = OldN, max_n = OldMaxN} = OldState) ->
  +    maybe_stop_timer(OldState),
       NewN = N - (OldMaxN - OldN),
  -    OldState#state{interval = I, delay_between_executions = D, n = NewN, max_n = MaxN}.
  +    NewState = OldState#state{interval = I, delay_between_executions = D, n = NewN, max_n = MaxN, tref = undefined},
  +    maybe_start_timer(NewState).
  +
  +maybe_start_timer(#state{delay_between_executions = 0, tref = undefined} = State) ->
  +    State#state{can_run_fn = true};
  +maybe_start_timer(#state{delay_between_executions = D, tref = undefined} = State) ->
  +    {ok, TRef} = timer:send_interval(D, delay_between_executions),
  +    State#state{can_run_fn = false, tref = TRef}.
  +
  +maybe_stop_timer(#state{tref = undefined}) ->
  +    ok;
  +maybe_stop_timer(#state{tref = TRef}) ->
  +    {ok, cancel} = timer:cancel(TRef).
   
   maybe_run_fn(#state{schedule = [], schedule_reversed = []} = State) ->
       State;
  
positive.code:          handle_call/3,
           handle_info/2,
           handle_cast/2,
           handle_continue/2]).
  
  -define(DEFAULT_MSG_TIMEOUT, 60000).%% one minute
  
  
negative.code: handle_continue(maybe_run_fn, State) ->
      NewState = maybe_run_fn(State),
      {noreply, NewState, timeout(NewState)}.
  
  format_status(_Opt, [_PDict, State]) ->
      ScheduleLen=length(State#state.schedule),
      ScheduleRevLen=length(State#state.schedule_reversed),
      State1=setelement(#state.schedule,State,ScheduleLen),
      setelement(#state.schedule_reversed,State1,ScheduleRevLen).
  %%------------------------------------------------------------------------------
  %% internal functions
  %%------------------------------------------------------------------------------
  