[erlang-questions] gen_statem confusion

Vans S <>
Thu Jan 19 04:01:07 CET 2017



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.





On Wednesday, January 18, 2017 7:27 PM, Fred Hebert <> wrote:
On 01/18, Vans S wrote:

>Would using a timeout or state_timeout of 0 provide the same guarantees as using next_event?
>Looking at the API it seems state_timeout maybe just shortform for {next_event, state_timeout, ..}
>
No.

A regular timeout would not trigger if messages are received or waiting 
in the mailbox

A next_event timeout works as follows according to the docs.

>  If the value is 0 no timer is actually started, instead the the 
>  time-out event is enqueued to ensure that it gets processed before 
>  any not yet received external event.

Already received external events and enqueued next_events will likely 
run before state timeouts.


More information about the erlang-questions mailing list