Guest User

Untitled

a guest
Nov 18th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. defmodule Archiver do
  2. # function that handles list of items to archive
  3. def archive([_h | _t] = items) do
  4. Enum.map(items, fn(item) -> Task.async(&archive_thing(&1)) end) # run a short lived task for each item
  5. |> Enum.map(&Task.await/1) # collect a result for each item and return a list of results
  6. end
  7.  
  8. # function to handle each individual itemd
  9. defp archive_thing(_t) do
  10. :timer.sleep(:rand.uniform(10000))
  11. end
  12. end
Add Comment
Please, Sign In to add comment