defmodule KVServer.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
def start(_type, _args) do
# List all child processes to be supervised
# port = String.to_integer(System.get_env("PORT") || raise "missing $PORT environment variable")
children = [
# Starts a worker by calling: KVServer.Worker.start_link(arg)
# {KVServer.Worker, arg},
{Task.Supervisor, name: KVServer.TaskSupervisor},
{Task, fn -> KVServer.accept(4040) end}
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: KVServer.Supervisor]
Supervisor.start_link(children, opts)
end
end
:one_for_one
,通过上面的代码,我们可以看出该应用启动了两个进程,当其中一个crash时,只会重启自身的进程
:one_for_all
,其中一个子进程crash时,重启所有子进程
:rest_for_all
, 按顺序重启当前进程之后的所有进程