The model - what is a task?

Instead of directly calling the spawn and spawn_link functions, we have another option available to us as a part of the standard Elixir BEAM functions. We can instead use the functionality around calling tasks for our one-off processes instead of trying to call kernel-level functions to spawn things asynchronously. The task module in Elixir provides a couple of handy functions (and we'll dive into some of this functionality in greater detail when we start talking about supervisors as well), but we'll primarily be concerned with Task.async/1, Task.async/3, and Task.await/1.

Task.async/1 is very simple; it just takes in the function that you want it to run and executes it as if it were being executed via spawn. Let's ...

Get Phoenix Web Development 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.