<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>