[erlang-questions] gen_statem confusion

Raimo Niskanen <>
Thu Jan 19 11:13:48 CET 2017


On Thu, Jan 19, 2017 at 11:59:37AM +0300, Alex S. wrote:
> 
> > 19 янв. 2017 г., в 6:01, Vans S <> написал(а):
> > 
> > 
> > 
> > This wording is really confusing:
> > 
> >> instead the the time-out event is enqueued to ensure 
> >> that it gets processed before any not yet received 
> >> external event
> > Because when I tried a test case
> > 
> > init() ->
> >  send(self(), hi),
> >  {_,_,_,0}.  %0 timeout basically
> > 
> > The 0 timeout procced before the 'hi' message.
> > Using 1 as the timeout, 'hi' message procs first.
> > 
> > But it says not yet received external event.  To me send() seems like 
> > an external event. Hence confusing.
> Well, it was sent, but not yet received by the gen_statem’s main loop.

Perfectly correct.

While gen_statem processes enqueued events it is guaranteed to not enter a
receive statement, so no new messages are received until after ther
state_timeout 0 message.

Other enqueued messages that are being processed such as next_event
messages will be processed before a state_timeout 0 message.

So if you in a state callback insert more next_event messages these are
inserted first in the queue, and a state_timeout 0 message is inserted last
in the queue.
-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list