Empty process mailbox in Erlang

when you send a message to the shell process, you can clear all messages by calling: c:flush().

  C: \ Windows \ System32> erl
 Eshell V5.9 (abort with ^ G)
 1> self ()!  josh.
 josh
 2> self ()!  me.
 me
 3> self ()!  you.
 you
 4> flush ().
 Shell got josh
 Shell got me
 Shell got you
 ok
 5>

In my opinion, this frees up the shell process mailbox. What is the equivalent way to empty the mailbox of any erlang process?

+4
source share
1 answer

This function should clear all messages from the mailbox (in any process when you call it):

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

All Articles