less than 1 minute read

when terminal hangs waiting for a message in OTP

Yesterday I attended an Elixir meetup where they were demonstrating how we send a message and receive it using receive block. This demo was shown referring to Documentation. During demo I saw a screen which was hanged because no message received. To continue, presentor pressed ctrl + c twice and forcefully stopped the process and started iex again.

In this post we see more advance part of message passing. When terminal hangs waiting for message, how to send a message to that process.

This is my journey about what all I tried and the learnings.

Elixir OTP process message passing

example for other

Elixir OTP process message passing

hanged / waiting for a message

Elixir OTP process message passing

Elixir OTP process message passing

Now I started once again, keeping in mind I want to send message from another process.

So we have everything like before.

Elixir OTP process message passing

Elixir OTP process message passing

Elixir OTP process message passing

Elixir OTP process message passing

Elixir OTP process message passing

Elixir OTP process message passing

Let us try to send a message from another terminal.

Elixir OTP process message passing

Elixir OTP process message passing

Elixir OTP process message passing

Now let us again make it wait for messages

Elixir OTP process message passing

waiting for messages

Elixir OTP process message passing

sent message from Cake

Elixir OTP process message passing

This might be a little confusing, let me try to create a Video recording that will be more easy to understand.