<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hi </span><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Your return of open(timeout, State) will clean the timeout value.</div>

<div style="font-family:arial,sans-serif;font-size:13px">You may change </div><div class="im" style="font-family:arial,sans-serif;font-size:13px"><div><br></div><div><div><div>open(timeout, State) -></div><div>    do_lock(),</div>

</div><div>    {next_state, locked, State}.</div></div><div><br></div></div><div style="font-family:arial,sans-serif;font-size:13px">to</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">

<div><div>open(timeout, State) -></div><div>    do_lock(),</div></div><div>    {next_state, locked, State};</div><div><div>open(_Event, State) -></div><div>   {next_state, open, State, 30000}.</div></div></div><div style="font-family:arial,sans-serif;font-size:13px">

<br></div><div style="font-family:arial,sans-serif;font-size:13px">Another note, timeout will occur unless a request or a message is received. </div><div style="font-family:arial,sans-serif;font-size:13px">If user keep to click button, it will not able to lock door ;p</div>

<div><br></div><div class="gmail_extra"><br clear="all"><div>---<br>Shian Wu<br><br></div>
<br><br><div class="gmail_quote">On Tue, Oct 22, 2013 at 10:37 AM, Bin Wang <span dir="ltr"><<a href="mailto:wbin00@gmail.com" target="_blank">wbin00@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr">There is an locked door example aboout gen_fsm in the Elrang Otp System Documentation.  I have a question about timeout. I will copy the code here first:<div><br></div><div><div>-module(code_lock).</div><div>


-behaviour(gen_fsm).</div><div>-export([start_link/1]).</div><div>-export([button/1]).</div><div>-export([init/1, locked/2, open/2]).</div><div><br></div><div>start_link(Code) -></div><div>    gen_fsm:start_link({local, code_lock}, code_lock, lists:reverse(Code, []).</div>


<div><br></div><div>button(Digit) -></div><div>    gen_fsm:send_event(code_lock, {button, Digit}).</div><div><br></div><div>init(Code) -></div><div>    {ok, locked, {[], Code}}.</div><div><br></div><div>locked({button, Digit}, {SoFar, Code}) -></div>


<div>    case [Digit|SoFar] of</div><div>    Code -></div><div>        do_unlock(),</div><div>        {next_state, open, {[], Code}, 30000};</div><div>    Incomplete when length(Incomplete)<length(Code) -></div>

<div>
        {next_state, locked, {Incomplete, Code}};</div><div>    _Wrong -></div><div>        {next_state, locked, {[], Code}}</div><div>    end.</div><div><br></div><div>open(timeout, State) -></div><div>    do_lock(),</div>


</div><div><div>    {next_state, locked, State}.</div></div><div><br></div><div>Here is the question: when the door is opened, if I press the button, the gen_fsm will have an {button, Digit} event at the state open. An error will occurs. But if I add these code after open function:</div>


<div><br></div><div>open(_Event, State) -></div><div>   {next_state, open, State}.</div><div><br></div><div>Then if I press the button in 30s, the timeout will not be occurs. The door will open forever. What should I do?</div>


<div><br></div><div>Thanks.</div><div><br></div><div>---</div><div>Bin Wang</div><div><br></div><div><br></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div></div>