Receive block not printing message

I have two tabs open in my terminal, both of which have iex running on them. I know running self on both the tabs would print their pid which returns the same pid.

In my tab1, I ran

receive do
 message -> IO.puts message
end

Since there are no messages in the mailbox, it keeps waiting for the new one to come. Please correct me if I am wrong here.

So the tab1 is waiting for a message to come and in my tab 2, I run

send(self, "Hello world")

Going back to tab1, I dont see it printing the message in the terminal. How ? and Why?

Starting iex in 2 shells is like starting two VM… If You want them to communicate, You need to manage distribution.

You might try some examples here

http://elixir-recipes.github.io/concurrency/connecting-nodes-same-machine/

2 Likes

Hmm, and I guess the PID is same for both the tab is because they are not os process but BEAM process?

Yes, they are not OS processes…