[erlang-questions] gen_fsm:send_event_after posts events in reverse order when timeout is zero

Joel Reymont <>
Mon Aug 8 14:17:09 CEST 2011


I'm processing TCP events in handle_info of my gen_fsm and posting them for processing with gen_fsm:send_event_after, using a timeout of 0, e.g.

handle_info({tcp, _Socket, Bin}, State, Bot = #bot{ cbk = Cbk, brain = Brain }) ->
    case pp:read(Bin) of
        none ->
            {next_state, State, Bot};
        Event ->
            Cbk:process(Brain, Event),
            gen_fsm:send_event_after(0, Event),
            {next_state, State, Bot}
    end;

It works as expected and the current state receives the event, except the order of events is reversed and I receive the last event first. 

Is this a bug or expected behavior?

I'm using a workaround for the time being:

            ({?MODULE, State})(Event, Bot)

This feels like a hack, though. 

Any suggestions for improvement?

	Thanks, Joel

--------------------------------------------------------------------------
- for hire: mac osx device driver ninja, kernel extensions and usb drivers
---------------------+------------+---------------------------------------
http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
---------------------+------------+---------------------------------------






More information about the erlang-questions mailing list