[erlang-questions] asynchronous api patterns for returning partial results ?

mabrek <>
Tue Oct 11 12:22:17 CEST 2011


Hello.

Are there good examples of asynchronous api in Erlang for returning
partial results?
Sometimes I need to return more than a single result from a gen_server.
gen_server:call with gen_server:reply isn't suitable for this because
gen_server:reply can be called only once per gen_server:call.

Desired behaviour can be emulated with:

Ref = make_ref(),
gen_server:cast(ServerName, {self(), Ref, Request}),
receive_results(Ref).

receive_results(Ref) ->
    receive
        {Ref, done} ->
            ok;
        {Ref, PartialResult} ->
            do_something_with(PartialResults),
            receive_results(Ref)
    end.

Is it a good way to receive several results from another process?

Regards,
Anton Lebedevich.



More information about the erlang-questions mailing list