[erlang-questions] gen_server cast question
Ladislav Lenart
lenartlad@REDACTED
Wed Jan 31 16:20:23 CET 2007
Hello,
I was browsing erlang (library) sources and found the
following in gen_server module:
do_send(Dest, Msg) ->
case catch erlang:send(Dest, Msg, [noconnect]) of
noconnect ->
spawn(erlang, send, [Dest, Msg]);
Other ->
Other
end.
do_send is called for example from gen_server:cast/2.
I know what the code above does, but don't understand
how the following can work:
gen_server:cast(Ref, msg1),
gen_server:cast(Ref, msg2),
gen_server:cast(Ref, msg3)
Suppose that Ref points to a process which resides on
the node that is not yet connected to the current node.
When the first cast is evaluated, noconnect is returned
and new process is spawned that sends the message msg1
to Ref. If the second cast is also evaluated before the
connection to the node is established, second process
is spawned that sends the message msg2 to Ref.
I think that there is a possibility that Ref will not
receive messages msg1, msg2 and msg3 in expected order
because of the internal spawning.
What am I missing here?
Ladislav Lenart
More information about the erlang-questions
mailing list