Skip to Main Content
Mastering Elixir
book

Mastering Elixir

by André Albuquerque, Daniel Caixinha
July 2018
Intermediate to advanced content levelIntermediate to advanced
574 pages
14h 7m
English
Packt Publishing
Content preview from Mastering Elixir

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 ...

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

Testing Elixir

Testing Elixir

Andrea Leopardi, Jeffrey Matthias

Publisher Resources

ISBN: 9781788472678Supplemental Content