к
Size: a a a
к
к
к
Process.alive?(__MODULE__) ?AN
к
к
defmodule T do
use GenServer
require Logger
@lifetime 100
# run this in repl
def test do
ping()
:timer.sleep(@lifetime)
ping()
end
def ping do
unless Process.whereis(__MODULE__) do
Logger.info("starting")
GenServer.start_link(__MODULE__, [], name: __MODULE__)
end
Logger.info("before call")
GenServer.call(__MODULE__, :ping)
end
def init([]) do
{:ok, [], @lifetime}
end
def handle_call(:ping, _, []) do
Logger.info("in call")
{:reply, :ok, [], @lifetime}
end
def handle_info(:timeout, []) do
Logger.info("timeout")
{:stop, :normal, []}
end
def terminate(:normal, []) do
Logger.info("terminate")
end
end
# 14:34:54.216 [info] starting
# 14:34:54.217 [info] before call
# 14:34:54.217 [info] in call
# 14:34:54.326 [info] terminate
# 14:34:54.326 [info] starting
# 14:34:54.326 [info] before call
# 14:34:54.326 [info] in call
# 14:35:40.792 [info] in call
# 14:35:40.902 [info] timeout
# 14:35:40.902 [info] terminate
# 14:35:40.902 [info] starting
# 14:35:40.902 [info] before call
# 14:35:40.902 [info] in call
# 14:35:41.011 [info] timeout
# 14:35:41.011 [info] terminateк
к
к
VS
gproc,IK
к
к
к
к
VS
GenServer.call({:via, ...}, _)catch, без lookup,call в вызов одной функциик
к
DR
Z
@impl true при объявлении функции? никак не могу нагуглить