[erlang-questions] Re: testing asynchronous code

Scott Lystig Fritchie <>
Thu Apr 22 22:47:32 CEST 2010

Matthew Sackman <> wrote:

ms> [...] gen_server: eg, and this one turns out to be very useful: "if you
ms> return 'stop' from some handle_* callback *and* a reply term,
ms> gen_server will wait until *after* the terminate callback has
ms> completed *before* sending the reply", [...]

Oh, I didn't know about that.  Then again, I think I can count in many
years the number of times that I've used the 'stop' tuple, in either
form, on only two or three fingers.

Regarding sending messages to yourself, in general, you should worry
about message order/interleaving with messages from other parties.

In the specific case of a long-running init phase (longer than a
supervisor will tolerate), interleaving isn't a worry.  If I have a
long-running init phase, the server sends itself a message from inside
the MyCallBackModule:init() function.  Jay's approach, sending the
message after MyCallBackModule:init() has returned but before
start_link() or start() returns the server's PID to the outside world,
is almost the same thing.


More information about the erlang-questions mailing list