Long-running Processes

Learn how to deal with long-running processes.

We'll cover the following

Define a new module

To see how linking processes and trapping exits behave, we need processes that hang around long enough for us to observe them. IEx is a long-running process that is readily available, but we’ll need to spawn others for it to interact with.

To do that, let’s define a new module at lib/islands_engine/demo_proc.ex. All we need is a single function that implements an infinite recursion. We call it the loop/0 function. In the middle, we use receive/1 to retrieve the next message from the mailbox:

Get hands-on with 1200+ tech skills courses.