Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/elixir/lib/task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1248,9 +1248,10 @@ defmodule Task do
{ref, nil}
end)

ref_count = map_size(refs)
on_timeout = Keyword.get(opts, :on_timeout, :nothing)
timeout = Keyword.get(opts, :timeout, 5_000)
limit = Keyword.get(opts, :limit, map_size(refs))
limit = min(Keyword.get(opts, :limit, ref_count), ref_count)
timeout_ref = make_ref()

timer_ref =
Expand Down
15 changes: 15 additions & 0 deletions lib/elixir/test/elixir/task_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,21 @@ defmodule TaskTest do
[{task2, nil}, {task3, {:exit, :normal}}]
end

test "returns once all tasks have replied below limit" do
parent = self()

pid =
spawn(fn ->
task = Task.async(fn -> :done end)
result = Task.yield_many([task], limit: 2, timeout: :infinity)
send(parent, {self(), result})
end)

on_exit(fn -> Process.exit(pid, :kill) end)

assert_receive {^pid, [{%Task{}, {:ok, :done}}]}, 500
end

test "returns results from multiple tasks with limit and on timeout" do
Process.flag(:trap_exit, true)
task1 = Task.async(fn -> Process.sleep(:infinity) end)
Expand Down
Loading