[erlang-questions] embedded timeouts
Bartłomiej Puzoń
bartlomiej@REDACTED
Mon Jul 5 15:37:49 CEST 2010
Yes, it is an intended behaviour. The receive's "after" closure applies if and only if there is no message to match
for the receive construct within a given amount of time.
----- "info" <info@REDACTED> escribió:
> The problem is that the "after Timeout" closure is never called. The
> loop never stops !
> John
>
> info wrote:
> > Hi all,
> > Why the first timeout never happens ?
>
> Does the function in init/1 receive a message?
> If it does, and loop/1 is called, it is no longer inside
> the receive clause, and the 'after' clause will not
> execute (it simply means, do this if no message has arrived
> within Timeout milliseconds).
>
> If no message is sent to the receive clause in init/1,
> loop() will never be called.
>
> BR,
> Ulf W
>
> > How must be structured this code in order to have two timeouts ?
> >
> > init(Timeout)- >
> > receive
> > ...
> > loop(),
> > after Timeout - >
> > ...
> > end.
> >
> > loop()- >
> > ...
> > send(Message),
> > receive after 1000 - > 0 end
> > loop().
> >
>
>
> --
> Ulf Wiger
> CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd
> http://www.erlang-solutions.com
--
Bartłomiej Puzoń
Erlang Solutions
bartlomiej.puzon@REDACTED
More information about the erlang-questions
mailing list