limiting gen_server
Micha
micha-1@REDACTED
Sun Aug 9 11:17:22 CEST 2009
Hi,
I want to restrict the simultanous calls my gen_server handles, since it calls
a network service itself and should not flood it :-)
I do it that way:
I keep a counter in the state and when the counter reaches the maximum I do
the following:
%% normal handling:
handle_info({udp, Socket, IPtuple, InPortNo, Packet}, State)
when State#state.cnt < ?LIMIT -> spawn(fun() -> ... end), ...;
%% max reached:
handle_info({udp, _Socket, _IPtuple, _InPortNo, _Packet} = Msg, State) ->
erlang:send_after(random:uniform(20)+10, self(), Msg),
{noreply, State};
is this o.k. ?
cheers,
Michael
More information about the erlang-questions
mailing list