Why would callers timeout (if using cast), is b/c the flush would prevent the gen_server from sending a reply ?<br><br><div class="gmail_quote">On Mon, Oct 15, 2012 at 3:36 PM, Gleb Peregud <span dir="ltr"><<a href="mailto:gleber.p@gmail.com" target="_blank">gleber.p@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mon, Oct 15, 2012 at 7:31 PM, AD <<a href="mailto:straightflush@gmail.com">straightflush@gmail.com</a>> wrote:<br>

> Hello,<br>
><br>
>  I have a use case where I would like to flush() the Mailbox in a loop.  I<br>
> have a process that takes about 500ms to execute, and i would like the<br>
> process to operate on batches of messages from the Mailbox rather than 1 at<br>
> a time.  Since the sender can push messages to the mailbox at tens of<br>
> messages/sec and I would like to preserve order, the most efficient way<br>
> right now I think of is to take messages off the mailbox in batches.<br>
><br>
> If there is a process sending to a gen_server:cast at , say, 10 messages/sec<br>
> , can i use flush to consume all 10 messages from teh mailbox at once?<br>
> Something like<br>
><br>
> flush() -><br>
>         receive<br>
>                 _ -> flush()<br>
>         after<br>
>                 0 -> ok<br>
>         end.<br>
<br>
</div></div>Of course you can. The code is correct as well. There are two problems here:<br>
1) It will consume gen_server:calls, hence callers will timeout<br>
2) It will consume sys messages, hence e.g. sys:get_status/1 won't work<br>
<br>
Cheers,<br>
Gleb Peregud<br>
</blockquote></div><br>