receive pitfall

Ulf Wiger ulf.wiger@REDACTED
Tue Nov 25 12:41:42 CET 2003


On Tue, 25 Nov 2003 13:23:36 +0200, HEINRICH VENTER 
<HEINRICH.VENTER@REDACTED> wrote:

> Hi again List
>
> A pitfall I have stepped in twice now, and I thought I'd share :)
>
> Be careful of a general term in your receive statements!  Your general 
> term WILL catch anything and everything, including messages that might 
> be intended for the same process in a different "state".  This is 
> something you have to be especialy weary of when you have more than one 
> receive statement in the same process, but perhaps in different 
> functions.

You may want to have one state (e.g. an idle() state) where unknown
messages are handled/discarded, and then stick to selective receive
in the substates. As you've found, introducing catch-alls in the sub-
states can have serious side-effects. One of the great things about
Erlang is the possibility to encapsulate dialogues using selective
receive. This is the reduction of the event/state matrix that
Mike Williams was talking about at EUC2003.

/Uffe
-- 
Ulf Wiger, Senior System Architect
EAB/UPD/S



More information about the erlang-questions mailing list