Keep Your Channels Asynchronous

Elixir is a parallel execution machine. Each Channel can leverage the principles of OTP design to execute work in parallel with other Channels, since the BEAM executes multiple processes at once. Every message processed by a Channel, whether incoming or outgoing, must go through the Channel process in order to execute. It’s possible for this to stop working well if we’re not careful about how our Channel is designed. This is easiest to see when we have an example of the problem in front of us.

We’ll leverage our existing StatsChannel to see the effect of process slowness. Let’s add a new message handler that responds very slowly.

 def​ handle_in(​

Get Real-Time Phoenix now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.