[erlang-questions] gen_statem next_event and appending to the event queue

Frans Schneider fchschneider@REDACTED
Wed Oct 4 11:03:33 CEST 2017


Dear list,

I have a state machine which implements the RTPS reader locator [1]. 
Basically, it has a list of unsent changes which should be send one by 
one to some transport. If the list is empty, the state becomes idle, 
otherwise it keeps the state pushing and uses the state callback action 
{next_event, internal, can_send} to process the next change from the list.
However, the state machine also has to respond to some other events like 
the one which will replace the list with unsent changes with a new one 
(this is according to the specs.) But, since the callback action 
next_event inserts events in front of the event queue, an event like 
(re)setting the unsent changes list is only processed after all internal 
events have been processed.
Adding events to the back of the queue can of course be done using a 
gen_statem:cast or a simple '!', but I would like to use a callback 
action for this as well, which looks tidier and feels better. What about 
adding an action {add_event, EventType, EventContent}?

Frans

[1] http://www.omg.org/spec/DDSI-RTPS/2.2/



More information about the erlang-questions mailing list