[erlang-questions] gen_statem, postpone and repeat_state

Raimo Niskanen raimo+erlang-questions@REDACTED
Thu Apr 19 15:24:53 CEST 2018

On Thu, Apr 19, 2018 at 02:47:48PM +0200, Frans Schneider wrote:
> It was because with repeat_state the enter state call is triggered which 
> suggests a start from fresh state entry. It makes sense to me to replay 
> postponed events in this situation.

Well, maybe...  Now repeat_state is defined as keep_state + repeat state
enter call, and also repeating postponed events could have been an option.
But that would break the underlying assumption of what is a state change:

The idea behind for postponing events and re-trying them after a state
change is that the code that handles events should change for a re-try to
be worth doing.  And if you stay in the same state you stay in the same
event handler (for callback mode state_functions), so the only way the
event handler could handle any events differently would be by using values
from the server Data to affect event matching, which makes those server
Data items in effect part of the actual State.  So you should have a
complex state instead with callback mode handle_event_function, and then
you would have a real state change.

In short:  Postponed event shall only be retried if State =/= OldState.

State enter calls are often used to start timers and other side effects, so
there is a need to be able to repeat them.

> On 04/19/2018 01:23 PM, Fred Hebert wrote:
> > On 04/19, Frans Schneider wrote:
> >> Hi list,
> >>
> >> I was assuming that with a repeat_state in gen_statem, all postponed 
> >> events would be re-evaluated. The docs give no explicit details about 
> >> this as far as I know. So, was my assumption wrong or would it be 
> >> logical for postponed events to be re-evaluated in this situation?
> >>
> > 
> > Postponed events are only replayed once the state has changed. repeating 
> > a state is not very different than something like
> > 
> >     handle_event(..., ..., current_state, Data) ->
> >         {next_state, current_state, Data}.
> > 
> > As such I think it's the right thing that postponed events are not 
> > replayed.
> > 
> > Regards,
> > Fred.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions


/ Raimo Niskanen, Erlang/OTP, Ericsson AB

More information about the erlang-questions mailing list