[erlang-questions] Is gen_server handle_info synchronous?

Chris Duesing <>
Wed Mar 3 22:03:48 CET 2010


Ok, thanks, that makes sense. It is obviously just an error in my code
then. I am sure I will be able to figure it out, but if you are
curious here is the link. I wasn't able to find any examples of how to
process streaming messages over tcp, so hopefully my approach isn't
too naive.

http://github.com/chrisduesing/iRLpact/blob/master/src/irlpact_connector.erl


On Wed, Mar 3, 2010 at 2:57 PM, Jeroen Koops <> wrote:
> Hi Chris,
> As far as I can tell, you're doing it right - handle_info is invoked
> synchronously (as are all gen_server's callbacks) and data saved in the
> state on one invocation to handle_info is available on a subsequent
> invocation. So the problem must be elsewhere - if you can share some of your
> source-code, maybe we can help.
>
>
> On Wed, Mar 3, 2010 at 9:37 PM, Chris Duesing <>
> wrote:
>>
>> I am working on some code that connects to a streaming data service
>> via gen_tcp:connect(). I am doing this from inside a gen_server to
>> benefit from OTP goodness. But, since it didn't seem to fit the
>> paradigm to have an infinite loop of reading from the socket with
>> recv, I left it as {active, once} and use handle_info to receive
>> blocks of data. Whenever I receive an incomplete message in
>> handle_info I just add it to the state, and then prepend it to the
>> data I receive the next time handle_info is called. Once I started
>> testing this code I am seeing that the data saved in the state is not
>> available the next time handle_info is called. I guess I assumed that
>> the gen_server would complete requests serially, is this not the case
>> or am I missing something?
>>
>> Thanks,
>>
>> Chris
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:
>>
>
>


More information about the erlang-questions mailing list