Parallel tasks

To help us understand how tasks work, we need a lazy cache mechanism. For this purpose, let's define a SlowCacheSupervisor process that delegates its put/2 and get/1 to the well-behaved CacheSupervisor already introduced, but before that, it sleeps for as many seconds as the media id it receives:

defmodule ElixirDrip.Storage.Supervisors.SlowCacheSupervisor do  @behaviour ElixirDrip.Behaviours.CacheSupervisor  alias ElixirDrip.Storage.Supervisors.CacheSupervisor, as: RealCache  def put(id, content), do: RealCache.put(id, content)  def get(id) do    secs_to_nap = case Integer.parse(id) do      {sleep_time, _} -> sleep_time      _ -> 1    end    Process.sleep(secs_to_nap * 1000)    RealCache.get(id)  end  # ...end

We now want to create a parallel text search ...

Get Mastering Elixir 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.