Blog Post: Star-Crossed LiveView Processes

Elixir has many powerful runtime features: processes, monitors, links, supervisors, and more. Sometimes, the hardest part is knowing which building blocks are the best ones for what we want to do. In this post I explore linking processes, trapping exits and running an async Task from a LiveView to solve a different kind of problem.

There’s been a lot written about running an async Task from a LiveView, but I wanted to build a ChatGPT-style UI where the data flows in, not just the final computed result.

In fact, I only care about the series of messages sent as side effects from the running Task. This difference changes how we approach the problem. In the post we see ho process linking is like Romeo & Juliette. When Juliette dies, it causes Romeo to die as well, the two are linked. This is the same for linked processes. But if we trap exits, our LiveView will be “notified” of a Task processes’ death without being killed. Turns out it’s both really simple and really powerful!
I :heart: the BEAM!