[erlang-questions] Update Pid State on a Timer

qp quantumpotato@REDACTED
Mon Dec 5 02:43:08 CET 2016


I am trying to update my process's state on a 3 second timer.

-define(INTERVAL, 3000).

start_link() ->
    gen_server:start_link(?MODULE, [], []).

action(Pid, Action) ->
  gen_server:call(Pid, Action).

init([]) ->
  erlang:send_after(?INTERVAL, self(), trigger),
  {ok, temple:new()}.

what I want to do is call this

handle_call({fight}, _From, Temple) ->
  NewTemple = temple:fight(Temple),
  {reply, NewTemple, NewTemple};

So I try

handle_info(trigger, _State) ->
   land:action(self(), {fight}),
   erlang:send_after(?INTERVAL, self(), trigger);

but I get

=ERROR REPORT==== 4-Dec-2016::19:00:35 ===
** Generic server <0.400.0> terminating
** Last message in was trigger
** When Server state == {{dict,0,16,16,8,80,48,
                               {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
                                []},
                               {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
                                 []}}},
                         []}
** Reason for termination ==
** {function_clause,[{land,terminate,
                           [{timeout,{gen_server,call,[<0.400.0>,{fight}]}},
                            {{dict,0,16,16,8,80,48,
                                   {[],[],[],[],[],[],[],[],[],[],[],[],[],[],
                                    [],[]},
                                   {{[],[],[],[],[],[],[],[],[],[],[],[],[],
                                     [],[],[]}}},
                             []}],
                           [{file,"src/land.erl"},{line,47}]}


What am I missing here?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161204/de68e2c1/attachment.htm>


More information about the erlang-questions mailing list