Skip to content

Commit

Permalink
Remove :shutdown from common validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sabiwara committed Jan 30, 2024
1 parent 0df5f2c commit d236b66
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
8 changes: 1 addition & 7 deletions lib/elixir/lib/task/supervised.ex
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ defmodule Task.Supervised do
timeout = Keyword.get(options, :timeout, 5000)
ordered = Keyword.get(options, :ordered, true)
zip_input_on_exit = Keyword.get(options, :zip_input_on_exit, false)
shutdown = Keyword.get(options, :shutdown, 5000)

unless is_integer(max_concurrency) and max_concurrency > 0 do
raise ArgumentError, ":max_concurrency must be an integer greater than zero"
Expand All @@ -209,17 +208,12 @@ defmodule Task.Supervised do
raise ArgumentError, ":timeout must be either a positive integer or :infinity"
end

unless (is_integer(shutdown) and shutdown >= 0) or shutdown == :brutal_kill do
raise ArgumentError, ":shutdown must be either a positive integer or :brutal_kill"
end

%{
max_concurrency: max_concurrency,
on_timeout: on_timeout,
timeout: timeout,
ordered: ordered,
zip_input_on_exit: zip_input_on_exit,
shutdown: shutdown
zip_input_on_exit: zip_input_on_exit
}
end

Expand Down
7 changes: 6 additions & 1 deletion lib/elixir/lib/task/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,15 @@ defmodule Task.Supervisor do
end

defp build_stream(supervisor, link_type, enumerable, fun, options) do
shutdown = Keyword.get(options, :shutdown, 5000)

unless (is_integer(shutdown) and shutdown >= 0) or shutdown == :brutal_kill do
raise ArgumentError, ":shutdown must be either a positive integer or :brutal_kill"
end

options = Task.Supervised.validate_stream_options(options)

fn acc, acc_fun ->
shutdown = options.shutdown
owner = get_owner(self())

Task.Supervised.stream(enumerable, acc, acc_fun, get_callers(self()), fun, options, fn ->
Expand Down
8 changes: 8 additions & 0 deletions lib/elixir/test/elixir/task/supervisor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ defmodule Task.SupervisorTest do
|> Task.Supervisor.async_stream(1..8, &exit/1, opts)
|> Enum.take(4) == [exit: {1, 1}, exit: {2, 2}, exit: {3, 3}, exit: {4, 4}]
end

test "does not allow streaming with invalid :shutdown", %{supervisor: supervisor} do
message = ":shutdown must be either a positive integer or :brutal_kill"

assert_raise ArgumentError, message, fn ->
Task.Supervisor.async_stream(supervisor, [], fn _ -> :ok end, shutdown: :unknown)
end
end
end

describe "async_stream_nolink" do
Expand Down
8 changes: 0 additions & 8 deletions lib/elixir/test/elixir/task_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -885,14 +885,6 @@ defmodule TaskTest do
end
end

test "does not allow streaming with invalid :shutdown" do
assert_raise ArgumentError,
":shutdown must be either a positive integer or :brutal_kill",
fn ->
Task.async_stream([1], fn _ -> :ok end, shutdown: :unknown)
end
end

test "streams with fake down messages on the inbox" do
parent = self()

Expand Down

0 comments on commit d236b66

Please sign in to comment.