Making Serial Code Concurrent with Tasks
Let’s learn how to handle long-running jobs in Elixir using async/await.
We'll cover the following...
The natural go-to concurrency construct for Elixir beginners is the process. Still, we generally want to incorporate proven features that have already addressed the subtle complexities of concurrency. We’ll cover processes here so we can put them in context when the inevitable edge cases do occur.
We’ve already spent some time using Elixir primitives for processes, but it bears repeating. We have access to the primitives to do the following:
-
Send messages with
send/2
. -
Spawn processes with the various versions of
spawn/n
andspawn_monitor/n
.
Typically, we’ll want our processes to be OTP processes because we’ll want to take advantage of the GenServer
lifecycle. Elixir can’t manage what it doesn’t know about.
We’ll rarely send messages with the send
variants, though we might use some of its close cousins. The following ...