concept Tasks in category elixir

appears as: Tasks, Tasks
The Little Elixir & OTP Guidebook

This is an excerpt from Manning's book The Little Elixir & OTP Guidebook.

Hang on to your seats, because this is only going to get better! There’s no need to go through the hassle of passing in the caller’s pid and setting up receive blocks. With Tasks, this is all handled for you.

Listing 8.5. Convenience function to run Blitzy workers in Tasks (lib/blitzy.ex)
defmodule Blitzy do

  def run(n_workers, url) when n_workers > 0 do
    worker_fun = fn -> Blitzy.Worker.start(url) end

    1..n_workers
      |> Enum.map(fn _ -> Task.async(worker_fun) end)
      |> Enum.map(&Task.await(&1))
  end

end