[erlang-questions] gen_fsm - timeout ?

Sean Hinde sean.hinde@REDACTED
Tue Sep 19 11:47:05 CEST 2006


On 19 Sep 2006, at 10:06, Chandru wrote:

> On 19/09/06, Sanjaya Vitharana <sanjaya@REDACTED> wrote:
> Hi ... ALL,
>
> Behavior: Gen FSM
>
> Scenario:
> Want to be in state "open" (see below) for limited time (assume 5  
> sec) until some EXPECTED event (as_E) comes, have to move to some  
> other state if the expected event not received in that time. All  
> other events should be ignored in state "open".
>
>
> One way around this is to not use the built-in timeout  
> functionality i.e drop the timeout value from the return value of  
> the callback function. You can use erlang:send_after/3  to send  
> yourself a message 5 seconds later.

Or you could use gen_fsm:send_event_after/2 which is designed to work  
seamlessly with the gen_fsm state handling. The timeout message is  
delivered directly into the current state callback.

If you need the original timer reference in the timeout message  
(Useful f you don't have another reference to the transaction that  
has timed out, and want to find it in e.g. a local ets table) then  
gen_fsm: start_timer/2 can be used.

Sean





More information about the erlang-questions mailing list