Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty Process Mail box in Erlang

when you send a message to the shell process, you can flush all messages out 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 thinking , this empties the mail box of the shell process. What is the equivalent way of emptying the mailbox of any erlang process ?

like image 629
Muzaaya Joshua Avatar asked Aug 16 '12 14:08

Muzaaya Joshua


1 Answers

This function should flush all messages from mailbox (in any process where you call it):

flush() ->
        receive
                _ -> flush()
        after
                0 -> ok
        end.
like image 70
stemm Avatar answered Sep 22 '22 18:09

stemm