Skip to content

Instantly share code, notes, and snippets.

@zacck-zz
Created November 16, 2017 10:54
Show Gist options
  • Save zacck-zz/54538d5b1cd7c1378508749d8fb4ed36 to your computer and use it in GitHub Desktop.
Save zacck-zz/54538d5b1cd7c1378508749d8fb4ed36 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment