Proper use of Task.async?

Maybe something like this

queries
|> Enum.map(fn query -> Task.async(Repo, :all, [query]) end) # starts queries
|> Enum.flat_map(fn task -> Task.await(task) end) # waits for them, collects results into one list

Note that Task.await by default waits for up to 5 seconds, then it times out (exits).

1 Like