[erlang-questions] embedded timeouts

info info@REDACTED
Mon Jul 5 15:33:48 CEST 2010


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


More information about the erlang-questions mailing list