[erlang-questions] gen_server aggregating calls/casts

Jonathan Leivent jleivent@REDACTED
Mon Jul 8 21:59:47 CEST 2013

On 07/08/2013 03:40 PM, Sergej Jurecko wrote:
> Easiest to explain with code:
> handle_call(Msg,From,State) ->
> {noreply,State#rec{calls = [From | State#rec.calls}};
> handle_call(replyall,_,State) ->
> [gen_server:reply(From,SomeMessage) || From <- lists:reverse(State#rec.calls)],
> {reply,ok,State}
> Queue instead of a list is probably better.
> Sergej

As I said: "It can't accumulate calls into its state because there are 
other unrelated calls/casts it can encounter prior to seeing all of the 
currently queued matching calls."  Also, it will never get anything like 
your replyall call.

Maybe I need two separate gen_server processes - one to just receive the 
requests and aggregate them into its state, then hand them off to the 
other, which handles both the aggregated requests and other calls/casts.

-- Jonathan

More information about the erlang-questions mailing list