A "sleep" command without "receive"
Mon Feb 2 10:14:51 CET 2004
On Mon, 2 Feb 2004 10:27:32 +0100, Corrado Santoro <csanto@REDACTED>
> Hi all,
> I've seen that to wait a timeout the statements I've to use are:
> after T-> ok
> I've also seen that timer:sleep/1 implements the same routine... but...
> I use this timeout in a process that, after the timeout, receives
> something from another process. If the sending process sends data before
> the receiving process calls timer:sleep, the latter function
> returns immediatelly, picking also the message. This is *not* the
> behaviour I want to implement.
> The problem is, obviously, that there is a "receive" statement in
> timer:sleep that "steals" incoming messages.
No, the above receive statement never consumes a message.
My guess is that you have some other receive statement in your
program that picks up the message. Either that, or you have
a rouge version of timer.beam. ;)
> Do you know how to wait a timeout without using "receive"?
There is no way to get a process to sleep without ending up in
a receive somewhere. The above method is safe and the one to use.
If messages get lost in your program, the bug must lie elsewhere.
Ulf Wiger, Senior System Architect
This communication is confidential and intended solely for the addressee(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you believe this message has been sent to you in error, please notify the sender by replying to this transmission and delete the message without disclosing it. Thank you.
E-mail including attachments is susceptible to data corruption, interruption, unauthorized amendment, tampering and viruses, and we only send and receive e-mails on the basis that we are not liable for any such corruption, interception, amendment, tampering or viruses or any consequences thereof.
More information about the erlang-questions