Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

The model - what if our process crashes?

We originally used spawn/1 to spawn our process, but there is a better way to do it overall. The trouble with just using spawn is that if something happens to that for any reason, there's not really a good way to track it! Let's test this out by replacing our behavior in the receive to instead just raise an exception:

process = fn ->  receive do    _ -> raise "Oh no!"  endend

Now in IEx, if we spawn this and attempt to do anything with it by sending it a message, we'll get an error message about a raised exception inside of a process:

iex(2)> pid = spawn(process)#PID<0.151.0>iex(3)> send(pid, :test):test18:08:16.958 [error] Process #PID<0.151.0> raised an exception** (RuntimeError) Oh no! (stdlib) erl_eval.erl:668: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content