<div dir="ltr">I am sorry I don't quite understand the problem. This is my understanding of the problem:<div><br></div><div>- You can receive 4 different types of messages: 'start', 'stop', {input,Data} and junk.</div>
<div>- When you process input you take a known, specific number of {input,Data} messages from the queue, waiting if necessary to get them all.</div><div>- You want to throw away all unknown (junk) messages.</div><div>- 'Start'/'stop' messages act as some form of priority switches and if the last of then to arrive was a 'start' when you are ready to process then you will start processing, otherwise you will wait for a 'start' message to start processing.</div>
<div><br></div><div>Is this correct or have I misunderstood you? Are there any more rules for the start/stop messages, for example they come in pairs or you count them, or do they just turn the process switch on/off? How long time does the processing take? Not so much in seconds but in expected messages arriving during that period.</div>
<div><br></div><div>You will always get race conditions, for example you decide to start processing but before you begin a 'stop' will arrive which you ignore till later. How critical is the "exact" timing of processing the 'start'/'stop' messages?</div>
<div><br></div><div>If this is what you mean then I think I may have a solution.</div><div><br></div><div>Robert</div><div><br><div class="gmail_quote">2008/8/5 Vlad Dumitrescu <span dir="ltr"><<a href="mailto:vladdu55@gmail.com">vladdu55@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div dir="ltr">Hi all,<br><br>I have an example of a receive where I don't seem to be able to use the usual "dump any unrecognized messages" catch-all clause. I think it is also an example where channels could be useful, but the main question is whether I am missing the obvious or not.<br>

<br>I have a process that takes {input, Data} messages from its mailbox and processes them (not necessarily one at a time). Flow control is implemented as a pair of 'start'/'stop' messages. The way I implemented the main loop is (simplified)<br>

<br>  receive<br>    start->Running = true, loop();<br>    stop->Running = false, loop()<br>  after 0 -> <br>      if Running -> process_one_step(), loop();<br>         true -> loop()<br>      end<br>  end,<br>

<br>where the process_one_step() function may call<br><br>  receive<br>    {input, Data} -> ...<br>  end<br><br>one or several times (it is configurable by the clients).<br><br>It seems to me that there is no place where I can put a '_->...;' clause without creating problems. So I'd like to ask if anyone sees another way to structure this that will allow rogue messages to be discarded.<br>

<br>------<br>A solution that requires an EEP :-) is to introduce an extension to the receive statement that will explicitly  keep matched messages  in the  mailbox. For example<br><br>receive <br>  Pattern -> keep(), loop();<br>

  Msg ->  process(Msg), loop() <br>end<br><br>keep() is the extension that says "leave the message in the mailbox and proceed". This way process() will be called with all messages except those matching Pattern<br>

<br>Would something like that be useful, or are there already ways to achieve the same effect?<br><br>best regards,<br>Vlad<br><br></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br></div></div>