[erlang-questions] Update Pid State on a Timer

James Aimonetti james@REDACTED
Mon Dec 5 06:29:43 CET 2016


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


http://erlang.org/doc/man/gen_server.html#Module:handle_info-2

Compare the expected return values there to what you return in your
clause...


qp writes:

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


- --
James Aimonetti

Lead Systems Architect
"If Dialyzer don't care, I don't care"
2600HzPDX | http://2600hz.com
sip:james@REDACTED
tel:415.886.7905
irc:mc_ @ freenode
-----BEGIN PGP SIGNATURE-----

iQEcBAEBCAAGBQJYRPtHAAoJENTKa+JPXCVgE08H/3m3QPHveD/tJjJ9qzirF76g
aFFEGGKvAPjUJBTuoTZLTd8cLe9RdB9KaTObLpTwdr+tnXwTg7K1JLHh5qJGakGQ
RXH2hkWG56Mn5SCbVTPvQIUxEXM48jsi9WZZUqadez+FALxDxkAH1h07wCfU5KJS
ZVQqSh1JIuGBSV6iA8SZhWL9p04axIdwl9TUXFIDQsTLmGfblvuzIr9Cv1GpuaDe
tZ0JyyED/3W/2qIlhfxYTwpip5S8WayR3rznauJwDnoTEygkI3rzw6hSaYpo4zU6
t+a2RXb8KMixI06+PRBOXIpRee/OQx7vbjAtRUxYyIYC4krp7f/Gc5f5W8xrJYk=
=83kE
-----END PGP SIGNATURE-----



More information about the erlang-questions mailing list