September 2013
Intermediate to advanced
548 pages
12h 25m
English
Sometimes a receive statement might wait forever for a message that never comes. This could be for a number of reasons. For example, there might be a logical error in our program, or the process that was going to send us a message might have crashed before it sent the message. To avoid this problem, we can add a timeout to the receive statement. This sets a maximum time that the process will wait to receive a message. The syntax is as follows:
| | receive |
| | Pattern1 [when Guard1] -> |
| | Expressions1; |
| | Pattern2 [when Guard2] -> |
| | Expressions2; |
| | ... |
| | after Time -> |
| | Expressions |
| | end |
If no matching message has arrived within Time milliseconds of entering the receive expression, then the process will stop waiting ...
Read now
Unlock full access