[erlang-questions] Question about gen_fsm timeout

James Aimonetti james@REDACTED
Tue Oct 22 06:53:56 CEST 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Perhaps gen_fsm:send_event_after/2 would be useful?

http://erldocs.com/R16B02/stdlib/gen_fsm.html#send_event_after/2

On 10/21/2013 07:37 PM, Bin Wang wrote:
> 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:
> 
> -module(code_lock). -behaviour(gen_fsm). -export([start_link/1]). 
> -export([button/1]). -export([init/1, locked/2, open/2]).
> 
> start_link(Code) -> gen_fsm:start_link({local, code_lock}, 
> code_lock, lists:reverse(Code, []).
> 
> button(Digit) -> gen_fsm:send_event(code_lock, {button, Digit}).
> 
> init(Code) -> {ok, locked, {[], Code}}.
> 
> locked({button, Digit}, {SoFar, Code}) -> case [Digit|SoFar] of 
> Code -> do_unlock(), {next_state, open, {[], Code}, 30000}; 
> Incomplete when length(Incomplete)<length(Code) -> {next_state, 
> locked, {Incomplete, Code}}; _Wrong -> {next_state, locked, {[], 
> Code}} end.
> 
> open(timeout, State) -> do_lock(), {next_state, locked, State}.
> 
> 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:
> 
> open(_Event, State) -> {next_state, open, State}.
> 
> Then if I press the button in 30s, the timeout will not be occurs. 
> The door will open forever. What should I do?
> 
> Thanks.
> 
> --- Bin Wang
> 
> 
> 
> _______________________________________________ erlang-questions 
> mailing list erlang-questions@REDACTED 
> http://erlang.org/mailman/listinfo/erlang-questions
> 


- -- 
James Aimonetti
Lead Systems Architect
"I thought I fixed that"

2600Hz | http://2600hz.com
sip:james@REDACTED
tel:415.886.7905
irc:mc_ @ freenode
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iF4EAREIAAYFAlJmBOQACgkQ54NxaUq7OmCp6gD/RrMjVwrLO4QWwh5sAKqj1p4p
utwwxG7zUDDvaIFk/fUA/2U9Mj4WRd2Ep3lm+mFSMwRpw46/WO5JtWboTjNlUlc/
=dMGn
-----END PGP SIGNATURE-----



More information about the erlang-questions mailing list