Created
November 16, 2017 10:54
-
-
Save zacck-zz/54538d5b1cd7c1378508749d8fb4ed36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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