Collecting concurrent tasks results?

In this example, I am executing several queries, one by one using Task.async:

  locations= user_ids
  |> -> last_location(&1, params, client) end))

the above example will wait for each task to finish before executing the next one.

How can I not wait for each task, by starting all of tasks in different process and collect results of all tasks regardless of who is finished first?

I need to wait for all concurrent tasks before return result to client, how would I do that?

1 Like

trying doing

entries |> Enum.each(fn entry ->
pid = spawn(SomeModule, :somefunction, [])
send(pid, {self, entry})

here it will send the result to shell

1 Like

Your code will start a new task for each user_id and then after they are all started it will wait for them all to finish. The tasks will be run concurrently.

1 Like

Great! thanks for clarification

1 Like