[erlang-questions] Re: testing asynchronous code
Thu Apr 22 06:16:50 CEST 2010
>> You're right, the cast call spawns a process with a single call to
>> erlang:send/2, but that process may not get a chance to run before
>> the initializing process makes a gen_server:call.
> That's not my reading of the gen_server code at all. The do_send()
> function (which is what ultimately does the erlang:send() of the
> message) /only/ spawns a new function if erlang:send() returns
> 'noconnect', and that will only happen (if my understanding is
> if the process in question resides on a currently unconnected
> node. In
> the case of the example code given, that's not going to be the case
> since the gen_server was started by the same process doing the
> cast, and
> therefore even if it was started on a remote node we must already be
> connected to that node.
You _read_ the code, while I just glanced at it to double-check if
was providing misleading information. Your reading is correct, the
sight of the spawn just gave me a spasm of remorse and I retracted
Thankfully, my old code is correct and it is safe to cast directly
after receiving the Pid from init, before returning it to the caller.
> To address the earlier question that lead to this, my understanding is
> that if you have the following message sending:
> A -> B
> A -> C
> C -> B (dependant on message from A)
> then the message from A to B /is/ guaranteed to arrive before the
> message from C. Feel free to correct me on that though.
That is correct. And I am going to step off this thread before I
create any more misleading asides.
More information about the erlang-questions