Erlang Mailing Lists

Author Message

<  Erlang  ~  [still newbie] FSM, timeouts and ignoring events

sv75
Posted: Mon Oct 22, 2007 3:06 pm Reply with quote
User Joined: 19 Oct 2007 Posts: 10
I'm studying FSM sample from http://www.erlang.org/doc/design_principles/fsm.html
I wonder how to ignore any buttons pressed when door is open without using additional timers. Sample above just terminates its execution in this case because there is no open({button, Digit}, State) function. I can add
Code:
open({button, Digit}, State) ->
    io:format("button ignored~n", []),
    {next_state, open, State}; 

but it breaks timeout that was set before. And I cannot get remaining time to set it again.

Any advices, please? Functions start_timer/cancel_timer are marked as internal. Should I just get over it and use timer module?
View user's profile Send private message Send e-mail
francesco
Posted: Tue Oct 23, 2007 2:15 pm Reply with quote
User Joined: 07 Jul 2006 Posts: 249 Location: London
Try

Code:
open(_, State) ->
    {next_state, open, State};


instead...

Francesco
--
http://www.erlang-consulting.com
View user's profile Send private message Visit poster's website
sv75
Posted: Wed Oct 24, 2007 10:22 am Reply with quote
User Joined: 19 Oct 2007 Posts: 10
francesco wrote:
Try

Code:
open(_, State) ->
    {next_state, open, State};



Timeout still never happens. Ok, I can live with timer:apply_after...
View user's profile Send private message Send e-mail
francesco
Posted: Wed Oct 24, 2007 1:09 pm Reply with quote
User Joined: 07 Jul 2006 Posts: 249 Location: London
When you receive a message, you reset the timeout. The only way to avoid it is to use, as you suggest, the timer module.

Francesco
--
http://www.erlang-consulting.com
View user's profile Send private message Visit poster's website

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum