Max Lapshin
unread,Dec 6, 2012, 8:27:50 AM12/6/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to erlang-...@googlegroups.com
Если ты хочешь сыммитировать домофон, то всё таки нужно скорее два процесса:
один накапливает в течении таймаута кнопки от пользователя, другой хранит код.
Проверка осуществляется атомарно списком кнопок.
Если же ты иммитируешь пульт отключения ядерного заряда, то как-то так:
start_link(Codes) -> gen_server:start_link({local,?MODULE},?MODULE,[Codes],[]).
button(Code) -> gen_server:call(?MODULE, {button, Code}).
init([Codes]) -> {ok, Codes}.
handle_call({button, Code}, [Code]) ->
{stop, normal, {ok, world_saved}, []};
handle_call({button, Code}, [Code|Codes]) ->
{reply, {ok, next}, Codes};
handle_call({button, Code}, [OtherCode|_] = Codes) ->
{stop, booom, {error, wrong_code, OtherCode}, Codes}.
terminate(_,_) -> ok.