A "sleep" command without "receive"

Samuel Tardieu <>
Mon Feb 2 10:00:41 CET 2004


On  2/02, Corrado Santoro wrote:

| receive 
|   after T-> ok 
| end 
|  
| 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. 

You seem confused about what the above code does: it does not get any
incoming message and sleeps for T milliseconds, regardless of whether
an incoming message arrives in the mean time or is already present.

The behaviour you describe would correspond to:

  receive
    X -> X
  after T -> ok
  end

which is not the same thing. The code you gave says: "wait at maximum T
milliseconds for a message to arrive that matches *nothing*" (thus no
match is possible, and the process will wait for T milliseconds)

You are giving the time in milliseconds do you?

  Sam




More information about the erlang-questions mailing list