Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defmodule Archiver do
- # function that handles list of items to archive
- def archive([_h | _t] = items) do
- Enum.map(items, fn(item) -> Task.async(&archive_thing(&1)) end) # run a short lived task for each item
- |> Enum.map(&Task.await/1) # collect a result for each item and return a list of results
- end
- # function to handle each individual itemd
- defp archive_thing(_t) do
- :timer.sleep(:rand.uniform(10000))
- end
- end
Add Comment
Please, Sign In to add comment