[erlang-questions] Erlang Scheduler for Recurring Events

Magnus Klaar <>
Wed Aug 24 17:49:59 CEST 2011


On Wed, Aug 24, 2011 at 4:51 PM, Ladislav Lenart <> wrote:

> Hello.
>
>
> > I was told that the timeout=0 reply from init/1 is has some implicit
> > behavior that might be useful: it ensures that the
> > handle_info('timout', State) is called before any other messages can
> > be dispatched, which gives you a hook from init/1 that will run after
> > the call to gen_server:start_link has returned. Feels hacky, to me --
> > but the only way to handle certain cases.
>
> Just a side note to the special meaning of timeout=0 in init: the same
> applies to any message sent to self() from the init/1 function, because
> noone else knows my pid yet.
>
>
> Ladislav Lenart
>
>
Hi!

Returning a timeout of 0ms from the init/1 callback does not guarantee that
a timeout message is "sent" to the handle_info function before any other
messages are processed.

If you for example registered the process in the init/1 callback, in the
process registry or another facility that would make your process visible to
other processes, you may return from the init/1 callback with a non-empty
message queue. In this case these messages will be processed by your
gen_server, you will not receive a timeout message after this.

MVH Magnus Klaar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110824/93320630/attachment.html>


More information about the erlang-questions mailing list