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

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


By partial results I mean something like rows from database query.
In this case first process sends SQL "select columns from table" to
database driver.
driver:handle_cast({request, ...}, ...) encodes and sends the request
to socket and waits results from {active, true} socket.
driver:handle_info({tcp, _, Data}, ...) decodes result rows from Data
and sends them back to the first process as a separate messages.

On Tue, Oct 11, 2011 at 6:51 PM, Barco You <> wrote:
> What do you mean by partial results? I think it depends on what your
> callback handle_cast do, what kinds of partial results it will rerun.
>
> Best regards,
> Barco
>
> On Oct 11, 2011 6:22 PM, "mabrek" <> wrote:
>>
>> 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.
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list