summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2017-06-05 13:46:42 +0200
committerJosé Valim <jose.valim@plataformatec.com.br>2017-06-05 13:46:52 +0200
commitff476fb59fe223f755fa6c4ab16711679a66c05c (patch)
tree2fbb95d22721c7419999e9dfe74c4f42efdcdb2c
parent05b6fd23563d218c323ac52ed1b2effb19f22347 (diff)
downloadelixir-jv-no-supervisor-spec.tar.gz
Retire use of Supervisor.Specjv-no-supervisor-spec
-rw-r--r--lib/elixir/lib/file.ex2
-rw-r--r--lib/elixir/lib/task/supervisor.ex10
-rw-r--r--lib/elixir/test/elixir/supervisor_test.exs22
-rw-r--r--lib/ex_unit/lib/ex_unit.ex8
-rw-r--r--lib/ex_unit/lib/ex_unit/capture_server.ex13
-rw-r--r--lib/ex_unit/lib/ex_unit/event_manager.ex9
-rw-r--r--lib/ex_unit/lib/ex_unit/on_exit_handler.ex10
-rw-r--r--lib/ex_unit/lib/ex_unit/server.ex15
-rw-r--r--lib/iex/lib/iex/app.ex8
-rw-r--r--lib/iex/lib/iex/config.ex3
-rw-r--r--lib/logger/lib/logger.ex4
-rw-r--r--lib/logger/lib/logger/app.ex27
-rw-r--r--lib/logger/lib/logger/watcher.ex51
-rw-r--r--lib/logger/lib/logger/watcher_supervisor.ex61
-rw-r--r--lib/logger/test/logger/translator_test.exs7
-rw-r--r--lib/mix/lib/mix.ex9
-rw-r--r--lib/mix/lib/mix/project_stack.ex20
-rw-r--r--lib/mix/lib/mix/state.ex4
-rw-r--r--lib/mix/lib/mix/tasks/new.ex8
-rw-r--r--lib/mix/lib/mix/tasks_server.ex4
20 files changed, 150 insertions, 145 deletions
diff --git a/lib/elixir/lib/file.ex b/lib/elixir/lib/file.ex
index 8763e0ae6..b33731ef8 100644
--- a/lib/elixir/lib/file.ex
+++ b/lib/elixir/lib/file.ex
@@ -1260,7 +1260,7 @@ defmodule File do
Raises an error if retrieving or changing the current
directory fails.
"""
- @spec cd!(Path.t, (() -> res)) :: res | no_return when res: var
+ @spec cd!(Path.t, (() -> res)) :: res when res: var
def cd!(path, function) do
old = cwd!()
cd!(path)
diff --git a/lib/elixir/lib/task/supervisor.ex b/lib/elixir/lib/task/supervisor.ex
index efaa9344c..00ee816e7 100644
--- a/lib/elixir/lib/task/supervisor.ex
+++ b/lib/elixir/lib/task/supervisor.ex
@@ -53,11 +53,15 @@ defmodule Task.Supervisor do
"""
@spec start_link([option]) :: Supervisor.on_start
def start_link(opts \\ []) do
- import Supervisor.Spec
{restart, opts} = Keyword.pop(opts, :restart, :temporary)
{shutdown, opts} = Keyword.pop(opts, :shutdown, 5000)
- children = [worker(Task.Supervised, [], restart: restart, shutdown: shutdown)]
- Supervisor.start_link(children, [strategy: :simple_one_for_one] ++ opts)
+ child = %{
+ id: Task.Supervised,
+ start: {Task.Supervised, :start_link, []},
+ restart: restart,
+ shutdown: shutdown
+ }
+ Supervisor.start_link([child], [strategy: :simple_one_for_one] ++ opts)
end
@doc """
diff --git a/lib/elixir/test/elixir/supervisor_test.exs b/lib/elixir/test/elixir/supervisor_test.exs
index d52b30d21..5d5197f7a 100644
--- a/lib/elixir/test/elixir/supervisor_test.exs
+++ b/lib/elixir/test/elixir/supervisor_test.exs
@@ -6,7 +6,7 @@ defmodule SupervisorTest do
defmodule Stack do
use GenServer
- def start_link(state, opts) do
+ def start_link({state, opts}) do
GenServer.start_link(__MODULE__, state, opts)
end
@@ -33,14 +33,11 @@ defmodule SupervisorTest do
defmodule Stack.Sup do
use Supervisor
- def init({arg, opts}) do
- children = [worker(Stack, [arg, opts])]
- supervise(children, strategy: :one_for_one)
+ def init(pair) do
+ Supervisor.init([{Stack, pair}], strategy: :one_for_one)
end
end
- import Supervisor.Spec
-
test "generates child_spec/1" do
assert Stack.Sup.child_spec([:hello]) == %{
id: Stack.Sup,
@@ -51,10 +48,10 @@ defmodule SupervisorTest do
defmodule CustomSup do
use Supervisor,
- id: :id,
- restart: :temporary,
- start: {:foo, :bar, []},
- shutdown: 5000 # ignored
+ id: :id,
+ restart: :temporary,
+ start: {:foo, :bar, []},
+ shutdown: 5000 # ignored
def init(arg) do
arg
@@ -130,7 +127,7 @@ defmodule SupervisorTest do
end
test "start_link/2" do
- children = [worker(Stack, [[:hello], [name: :dyn_stack]])]
+ children = [{Stack, {[:hello], [name: :dyn_stack]}}]
{:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one)
wait_until_registered(:dyn_stack)
@@ -168,7 +165,8 @@ defmodule SupervisorTest do
assert Supervisor.count_children(pid) ==
%{specs: 0, active: 0, supervisors: 0, workers: 0}
- {:ok, stack} = Supervisor.start_child(pid, worker(Stack, [[:hello], []]))
+ child_spec = Supervisor.child_spec({Stack, {[:hello], []}}, [])
+ {:ok, stack} = Supervisor.start_child(pid, child_spec)
assert GenServer.call(stack, :pop) == :hello
assert Supervisor.which_children(pid) ==
diff --git a/lib/ex_unit/lib/ex_unit.ex b/lib/ex_unit/lib/ex_unit.ex
index 5333d1aa4..dc28ea8f0 100644
--- a/lib/ex_unit/lib/ex_unit.ex
+++ b/lib/ex_unit/lib/ex_unit.ex
@@ -126,12 +126,10 @@ defmodule ExUnit do
@doc false
def start(_type, []) do
- import Supervisor.Spec
-
children = [
- worker(ExUnit.Server, []),
- worker(ExUnit.CaptureServer, []),
- worker(ExUnit.OnExitHandler, [])
+ ExUnit.Server,
+ ExUnit.CaptureServer,
+ ExUnit.OnExitHandler
]
opts = [strategy: :one_for_one, name: ExUnit.Supervisor]
diff --git a/lib/ex_unit/lib/ex_unit/capture_server.ex b/lib/ex_unit/lib/ex_unit/capture_server.ex
index ff369574d..c23cfcd50 100644
--- a/lib/ex_unit/lib/ex_unit/capture_server.ex
+++ b/lib/ex_unit/lib/ex_unit/capture_server.ex
@@ -1,27 +1,28 @@
defmodule ExUnit.CaptureServer do
@moduledoc false
@timeout 30_000
+ @name __MODULE__
use GenServer
- def start_link() do
- GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
+ def start_link(_opts) do
+ GenServer.start_link(__MODULE__, :ok, name: @name)
end
def device_capture_on(device, pid) do
- GenServer.call(__MODULE__, {:device_capture_on, device, pid}, @timeout)
+ GenServer.call(@name, {:device_capture_on, device, pid}, @timeout)
end
def device_capture_off(ref) do
- GenServer.call(__MODULE__, {:device_capture_off, ref}, @timeout)
+ GenServer.call(@name, {:device_capture_off, ref}, @timeout)
end
def log_capture_on(pid) do
- GenServer.call(__MODULE__, {:log_capture_on, pid}, @timeout)
+ GenServer.call(@name, {:log_capture_on, pid}, @timeout)
end
def log_capture_off(ref) do
- GenServer.call(__MODULE__, {:log_capture_off, ref}, @timeout)
+ GenServer.call(@name, {:log_capture_off, ref}, @timeout)
end
## Callbacks
diff --git a/lib/ex_unit/lib/ex_unit/event_manager.ex b/lib/ex_unit/lib/ex_unit/event_manager.ex
index 05f603495..3580bdacb 100644
--- a/lib/ex_unit/lib/ex_unit/event_manager.ex
+++ b/lib/ex_unit/lib/ex_unit/event_manager.ex
@@ -11,9 +11,12 @@ defmodule ExUnit.EventManager do
internal statistics server for ExUnit.
"""
def start_link() do
- import Supervisor.Spec
- child = worker(GenServer, [], restart: :temporary)
- {:ok, sup} = Supervisor.start_link([child], strategy: :simple_one_for_one)
+ spec = %{
+ id: GenServer,
+ start: {GenServer, :start_link, []},
+ restart: :temporary
+ }
+ {:ok, sup} = Supervisor.start_link([spec], strategy: :simple_one_for_one)
{:ok, event} = :gen_event.start_link()
{:ok, {sup, event}}
end
diff --git a/lib/ex_unit/lib/ex_unit/on_exit_handler.ex b/lib/ex_unit/lib/ex_unit/on_exit_handler.ex
index 40423bc9d..e661f99c8 100644
--- a/lib/ex_unit/lib/ex_unit/on_exit_handler.ex
+++ b/lib/ex_unit/lib/ex_unit/on_exit_handler.ex
@@ -2,7 +2,9 @@ defmodule ExUnit.OnExitHandler do
@moduledoc false
@name __MODULE__
- def start_link do
+ use Agent
+
+ def start_link(_opts) do
Agent.start_link(fn -> %{} end, name: @name)
end
@@ -34,7 +36,7 @@ defmodule ExUnit.OnExitHandler do
Enum.reduce(callbacks, {nil, nil, nil}, &exec_on_exit_callback(&1, timeout, &2))
if is_pid(runner_pid) and Process.alive?(runner_pid) do
- send(runner_pid, :shutdown)
+ Process.exit(runner_pid, :shutdown)
receive do
{:DOWN, ^runner_monitor, :process, ^runner_pid, _error} -> :ok
end
@@ -51,8 +53,6 @@ defmodule ExUnit.OnExitHandler do
defp receive_runner_reply(runner_pid, runner_monitor, state, timeout) do
receive do
- {^runner_pid, nil} ->
- {runner_pid, runner_monitor, state}
{^runner_pid, error} ->
{runner_pid, runner_monitor, state || error}
{:DOWN, ^runner_monitor, :process, ^runner_pid, error} ->
@@ -81,8 +81,6 @@ defmodule ExUnit.OnExitHandler do
{:run, from, fun} ->
send(from, {self(), exec_callback(fun)})
on_exit_runner_loop()
- :shutdown ->
- :ok
end
end
diff --git a/lib/ex_unit/lib/ex_unit/server.ex b/lib/ex_unit/lib/ex_unit/server.ex
index a5f399683..228933216 100644
--- a/lib/ex_unit/lib/ex_unit/server.ex
+++ b/lib/ex_unit/lib/ex_unit/server.ex
@@ -1,32 +1,33 @@
defmodule ExUnit.Server do
@moduledoc false
+ @name __MODULE__
use GenServer
- def start_link() do
- GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
+ def start_link(_opts) do
+ GenServer.start_link(__MODULE__, :ok, name: @name)
end
def add_async_case(name) do
- GenServer.cast(__MODULE__, {:add_async_case, name})
+ GenServer.cast(@name, {:add_async_case, name})
end
def add_sync_case(name) do
- GenServer.cast(__MODULE__, {:add_sync_case, name})
+ GenServer.cast(@name, {:add_sync_case, name})
end
def cases_loaded do
- GenServer.call(__MODULE__, :cases_loaded)
+ GenServer.call(@name, :cases_loaded)
end
def take_async_cases(count) do
timeout = Application.fetch_env!(:ex_unit, :case_load_timeout)
- GenServer.call(__MODULE__, {:take_async_cases, count}, timeout)
+ GenServer.call(@name, {:take_async_cases, count}, timeout)
end
def take_sync_cases() do
timeout = Application.fetch_env!(:ex_unit, :case_load_timeout)
- GenServer.call(__MODULE__, :take_sync_cases, timeout)
+ GenServer.call(@name, :take_sync_cases, timeout)
end
## Callbacks
diff --git a/lib/iex/lib/iex/app.ex b/lib/iex/lib/iex/app.ex
index baf398702..953cc21a3 100644
--- a/lib/iex/lib/iex/app.ex
+++ b/lib/iex/lib/iex/app.ex
@@ -4,13 +4,9 @@ defmodule IEx.App do
use Application
def start(_type, _args) do
- import Supervisor.Spec
-
- children = [worker(IEx.Config, [])]
- options = [strategy: :one_for_one, name: IEx.Supervisor]
-
tab = IEx.Config.new()
- case Supervisor.start_link(children, options) do
+
+ case Supervisor.start_link([IEx.Config], strategy: :one_for_one, name: IEx.Supervisor) do
{:ok, pid} ->
{:ok, pid, tab}
{:error, _} = error ->
diff --git a/lib/iex/lib/iex/config.ex b/lib/iex/lib/iex/config.ex
index 4056dc470..721559efd 100644
--- a/lib/iex/lib/iex/config.ex
+++ b/lib/iex/lib/iex/config.ex
@@ -1,5 +1,6 @@
defmodule IEx.Config do
@moduledoc false
+ use Agent
@table __MODULE__
@agent __MODULE__
@@ -118,7 +119,7 @@ defmodule IEx.Config do
# Agent API
- def start_link() do
+ def start_link(_) do
Agent.start_link(__MODULE__, :handle_init, [@table], [name: @agent])
end
diff --git a/lib/logger/lib/logger.ex b/lib/logger/lib/logger.ex
index c0df9fada..7ac1ab1fa 100644
--- a/lib/logger/lib/logger.ex
+++ b/lib/logger/lib/logger.ex
@@ -505,7 +505,7 @@ defmodule Logger do
@spec add_backend(atom, keyword) :: Supervisor.on_start_child
def add_backend(backend, opts \\ []) do
_ = if opts[:flush], do: flush()
- case Logger.Watcher.watch(Logger, Logger.Config.translate_backend(backend), backend) do
+ case Logger.WatcherSupervisor.watch(Logger, Logger.Config.translate_backend(backend), backend) do
{:ok, _} = ok ->
Logger.Config.add_backend(backend)
ok
@@ -530,7 +530,7 @@ defmodule Logger do
def remove_backend(backend, opts \\ []) do
_ = if opts[:flush], do: flush()
Logger.Config.remove_backend(backend)
- Logger.Watcher.unwatch(Logger, Logger.Config.translate_backend(backend))
+ Logger.WatcherSupervisor.unwatch(Logger, Logger.Config.translate_backend(backend))
end
@doc """
diff --git a/lib/logger/lib/logger/app.ex b/lib/logger/lib/logger/app.ex
index cd618db31..b01edfe13 100644
--- a/lib/logger/lib/logger/app.ex
+++ b/lib/logger/lib/logger/app.ex
@@ -5,25 +5,28 @@ defmodule Logger.App do
@doc false
def start(_type, _args) do
- import Supervisor.Spec
-
otp_reports? = Application.get_env(:logger, :handle_otp_reports)
sasl_reports? = Application.get_env(:logger, :handle_sasl_reports)
threshold = Application.get_env(:logger, :discard_threshold_for_error_logger)
+ error_handler = {:error_logger, Logger.ErrorHandler, {otp_reports?, sasl_reports?, threshold}}
- options = [strategy: :rest_for_one, name: Logger.Supervisor]
- children = [worker(:gen_event, [{:local, Logger}]),
- worker(Logger.Watcher, [Logger, Logger.Config, []],
- [id: Logger.Config, function: :watcher]),
- supervisor(Logger.Watcher, [Logger.Config, :handlers, []]),
- worker(Logger.Watcher,
- [:error_logger, Logger.ErrorHandler,
- {otp_reports?, sasl_reports?, threshold}],
- [id: Logger.ErrorHandler, function: :watcher])]
+ children = [
+ %{
+ id: :gen_event,
+ start: {:gen_event, :start_link, [{:local, Logger}]},
+ modules: :dynamic
+ },
+ {Logger.Watcher, {Logger, Logger.Config, []}},
+ {Logger.WatcherSupervisor, {Logger.Config, :handlers, []}},
+ %{
+ id: Logger.ErrorHandler,
+ start: {Logger.Watcher, :start_link, [error_handler]}
+ }
+ ]
config = Logger.Config.new()
- case Supervisor.start_link(children, options) do
+ case Supervisor.start_link(children, strategy: :rest_for_one, name: Logger.Supervisor) do
{:ok, sup} ->
handlers = [error_logger_tty_h: otp_reports?,
sasl_report_tty_h: sasl_reports?]
diff --git a/lib/logger/lib/logger/watcher.ex b/lib/logger/lib/logger/watcher.ex
index faf238341..45ce4e29a 100644
--- a/lib/logger/lib/logger/watcher.ex
+++ b/lib/logger/lib/logger/watcher.ex
@@ -3,53 +3,6 @@ defmodule Logger.Watcher do
require Logger
use GenServer
- @name Logger.Watcher
-
- @doc """
- Starts the watcher supervisor.
- """
- def start_link(m, f, a) do
- options = [strategy: :one_for_one, name: @name, max_restarts: 30, max_seconds: 3]
- case Supervisor.start_link([], options) do
- {:ok, _} = ok ->
- _ = for {mod, handler, args} <- apply(m, f, a) do
- {:ok, _} = watch(mod, handler, args)
- end
- ok
- {:error, _} = error ->
- error
- end
- end
-
- @doc """
- Removes the given handler.
- """
- def unwatch(mod, handler) do
- child_id = {__MODULE__, {mod, handler}}
- case Supervisor.terminate_child(@name, child_id) do
- :ok ->
- _ = Supervisor.delete_child(@name, child_id)
- :ok
- {:error, _} = error ->
- error
- end
- end
-
- @doc """
- Watches the given handler as part of the watcher supervision tree.
- """
- def watch(mod, handler, args) do
- import Supervisor.Spec
- id = {__MODULE__, {mod, handler}}
- child = worker(__MODULE__, [mod, handler, args], id: id, function: :watcher, restart: :transient)
- case Supervisor.start_child(@name, child) do
- {:error, :already_present} ->
- _ = Supervisor.delete_child(@name, id)
- watch(mod, handler, args)
- other ->
- other
- end
- end
@doc """
Starts a watcher server.
@@ -57,8 +10,8 @@ defmodule Logger.Watcher do
This is useful when there is a need to start a handler
outside of the handler supervision tree.
"""
- def watcher(mod, handler, args) do
- GenServer.start_link(__MODULE__, {mod, handler, args})
+ def start_link(triplet) do
+ GenServer.start_link(__MODULE__, triplet)
end
## Callbacks
diff --git a/lib/logger/lib/logger/watcher_supervisor.ex b/lib/logger/lib/logger/watcher_supervisor.ex
new file mode 100644
index 000000000..1f9983eda
--- /dev/null
+++ b/lib/logger/lib/logger/watcher_supervisor.ex
@@ -0,0 +1,61 @@
+defmodule Logger.WatcherSupervisor do
+ @moduledoc false
+
+ use Supervisor
+ @name Logger.WatcherSupervisor
+
+ @doc """
+ Starts the watcher supervisor.
+ """
+ def start_link({m, f, a}) do
+ case Supervisor.start_link(__MODULE__, [], name: @name) do
+ {:ok, _} = ok ->
+ _ = for {mod, handler, args} <- apply(m, f, a) do
+ {:ok, _} = watch(mod, handler, args)
+ end
+ ok
+ {:error, _} = error ->
+ error
+ end
+ end
+
+ @doc """
+ Removes the given handler.
+ """
+ def unwatch(mod, handler) do
+ child_id = {__MODULE__, {mod, handler}}
+ case Supervisor.terminate_child(@name, child_id) do
+ :ok ->
+ _ = Supervisor.delete_child(@name, child_id)
+ :ok
+ {:error, _} = error ->
+ error
+ end
+ end
+
+ @doc """
+ Watches the given handler as part of the watcher supervision tree.
+ """
+ def watch(mod, handler, args) do
+ id = {__MODULE__, {mod, handler}}
+
+ spec = %{
+ id: id,
+ start: {Logger.Watcher, :start_link, [{mod, handler, args}]},
+ restart: :transient
+ }
+
+ case Supervisor.start_child(@name, spec) do
+ {:error, :already_present} ->
+ _ = Supervisor.delete_child(@name, id)
+ watch(mod, handler, args)
+ other ->
+ other
+ end
+ end
+
+ @doc false
+ def init(children) do
+ Supervisor.init(children, strategy: :one_for_one, max_restarts: 30, max_seconds: 3)
+ end
+end
diff --git a/lib/logger/test/logger/translator_test.exs b/lib/logger/test/logger/translator_test.exs
index 41a2ceff7..e44c76530 100644
--- a/lib/logger/test/logger/translator_test.exs
+++ b/lib/logger/test/logger/translator_test.exs
@@ -1,6 +1,5 @@
defmodule Logger.TranslatorTest do
use Logger.Case
- import Supervisor.Spec
defmodule MyGenServer do
use GenServer
@@ -713,7 +712,7 @@ defmodule Logger.TranslatorTest do
end
child_opts = [restart: :temporary, function: :"start link"]
- children = [Supervisor.Spec.worker(WeirdFunctionNamesGenServer, [], child_opts)]
+ children = [worker(WeirdFunctionNamesGenServer, [], child_opts)]
{:ok, sup} = Supervisor.start_link(children, strategy: :simple_one_for_one)
log = capture_log(:info, fn ->
@@ -769,4 +768,8 @@ defmodule Logger.TranslatorTest do
:proc_lib.init_ack({:ok, self()})
receive do: ({:EXIT, _, _} -> exit(:stop))
end
+
+ defp worker(name, args, opts \\ []) do
+ Enum.into(opts, %{id: name, start: {name, opts[:function] || :start_link, args}})
+ end
end
diff --git a/lib/mix/lib/mix.ex b/lib/mix/lib/mix.ex
index 597265d07..f9409030b 100644
--- a/lib/mix/lib/mix.ex
+++ b/lib/mix/lib/mix.ex
@@ -184,14 +184,7 @@ defmodule Mix do
@doc false
def start(_type, []) do
- import Supervisor.Spec
-
- children = [
- worker(Mix.State, []),
- worker(Mix.TasksServer, []),
- worker(Mix.ProjectStack, [])
- ]
-
+ children = [Mix.State, Mix.TasksServer, Mix.ProjectStack]
opts = [strategy: :one_for_one, name: Mix.Supervisor, max_restarts: 0]
Supervisor.start_link(children, opts)
end
diff --git a/lib/mix/lib/mix/project_stack.ex b/lib/mix/lib/mix/project_stack.ex
index 4b761f64f..8d353c75a 100644
--- a/lib/mix/lib/mix/project_stack.ex
+++ b/lib/mix/lib/mix/project_stack.ex
@@ -1,14 +1,15 @@
defmodule Mix.ProjectStack do
@moduledoc false
+ use Agent
@timeout 30_000
@typep file :: binary
@typep config :: keyword
@typep project :: %{name: module, config: config, file: file}
- @spec start_link :: {:ok, pid}
- def start_link() do
+ @spec start_link(keyword) :: {:ok, pid}
+ def start_link(_opts) do
initial = %{stack: [], post_config: [], cache: %{}}
Agent.start_link fn -> initial end, name: __MODULE__
end
@@ -72,9 +73,7 @@ defmodule Mix.ProjectStack do
end
end
- @doc """
- Runs the given function in the recursing root.
- """
+ @spec root((() -> result)) :: result when result: var
def root(fun) do
{top, file} =
get_and_update fn %{stack: stack} = state ->
@@ -121,11 +120,7 @@ defmodule Mix.ProjectStack do
end
end
- @doc """
- Enables the recursion for the project at the top of the stack
- during the given function.
- """
- @spec recur((... -> result)) :: result when result: var
+ @spec recur((() -> result)) :: result when result: var
def recur(fun) do
cast fn %{stack: [h | t]} = state ->
%{state | stack: [%{h | recursing?: true} | t]}
@@ -140,11 +135,6 @@ defmodule Mix.ProjectStack do
end
end
- @doc """
- Returns the module that started the recursion.
-
- Returns nil if not recursive.
- """
@spec recursing :: module | nil
def recursing do
get fn %{stack: stack} ->
diff --git a/lib/mix/lib/mix/state.ex b/lib/mix/lib/mix/state.ex
index 906ef5758..8e6095625 100644
--- a/lib/mix/lib/mix/state.ex
+++ b/lib/mix/lib/mix/state.ex
@@ -2,7 +2,9 @@ defmodule Mix.State do
@moduledoc false
@name __MODULE__
- def start_link() do
+ use Agent
+
+ def start_link(_opts) do
Agent.start_link(__MODULE__, :init, [], [name: @name])
end
diff --git a/lib/mix/lib/mix/tasks/new.ex b/lib/mix/lib/mix/tasks/new.ex
index a6beb5482..d90b8093d 100644
--- a/lib/mix/lib/mix/tasks/new.ex
+++ b/lib/mix/lib/mix/tasks/new.ex
@@ -424,12 +424,10 @@ defmodule Mix.Tasks.New do
use Application
def start(_type, _args) do
- import Supervisor.Spec, warn: false
-
- # Define workers and child supervisors to be supervised
+ # List all child processes to be supervised
children = [
- # Starts a worker by calling: <%= @mod %>.Worker.start_link(arg1, arg2, arg3)
- # worker(<%= @mod %>.Worker, [arg1, arg2, arg3]),
+ # Starts a worker by calling: <%= @mod %>.Worker.start_link(arg)
+ # {<%= @mod %>.Worker, arg},
]
# See https://hexdocs.pm/elixir/Supervisor.html
diff --git a/lib/mix/lib/mix/tasks_server.ex b/lib/mix/lib/mix/tasks_server.ex
index 3ca82b584..5efc4ea72 100644
--- a/lib/mix/lib/mix/tasks_server.ex
+++ b/lib/mix/lib/mix/tasks_server.ex
@@ -1,7 +1,9 @@
defmodule Mix.TasksServer do
@moduledoc false
- def start_link() do
+ use Agent
+
+ def start_link(_opts) do
Agent.start_link(fn -> %{} end, name: __MODULE__)
end