a
Size: a a a
a
a
к
a
stop
провозился часа 2 😊a
NK
ŹR
ŹR
a
a
a
use GenServer, restart: :transient
a
ŹR
ŹR
defmodule DynS.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
def start(_type, _args) do
# See https://hexdocs.pm/elixir/Supervisor.html
# for proper instructions
Supervisor.start_link(
[
# Add this exmpla worker using `mix aqua add otp.gs DynS.Worker`
# DynS.Worker
DynS.Supervisor
],
strategy: :one_for_one,
name: DynS.Application
)
end
end
defmodule MyWorker do
use GenServer, restart: :transient
def start_link(arg) do
GenServer.start_link(__MODULE__, arg)
end
def handle_info(:test, state) do
IO.inspect(:test)
{:stop, :normal, state}
end
end
defmodule DynS.Supervisor do
use DynamicSupervisor
def start_link(arg) do
DynamicSupervisor.start_link(__MODULE__, arg, name: __MODULE__)
end
def init(_arg) do
DynamicSupervisor.init(
strategy: :one_for_one
)
end
def start_child(name) do
# If MyWorker is not using the new child specs, we need to pass a map:
# spec = %{id: MyWorker, start: {MyWorker, :start_link, [foo, bar, baz]}}
spec = {MyWorker, name}
DynamicSupervisor.start_child(__MODULE__, spec)
end
end
ML
ŹR
a
a
a
ŹR