[erlang-questions] using flush() for batches from mailbox

AD straightflush@REDACTED
Mon Oct 15 19:31:38 CEST 2012


Hello,

 I have a use case where I would like to flush() the Mailbox in a loop.  I
have a process that takes about 500ms to execute, and i would like the
process to operate on batches of messages from the Mailbox rather than 1 at
a time.  Since the sender can push messages to the mailbox at tens of
messages/sec and I would like to preserve order, the most efficient way
right now I think of is to take messages off the mailbox in batches.

If there is a process sending to a gen_server:cast at , say, 10
messages/sec , can i use flush to consume all 10 messages from teh mailbox
at once?  Something like

flush() ->
        receive
                _ -> flush()
        after
                0 -> ok
        end.

TThanks

-AD
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121015/71af33ee/attachment.htm>


More information about the erlang-questions mailing list