原因:DOWN信息未发送到GenServer?

时间:2017-09-06 15:05:59

标签: elixir

我正在尝试使用GenServer,我刚刚创建了一个链接过程,并尝试将其删除,以了解如何使用handle_info param调用:DOWN

defmodule CSVServer do
use GenServer

import Logger
import Ecto.Query

def start_link(_opts \\ []) do
    GenServer.start_link(__MODULE__, %{}, name: __MODULE__)
end



def test!(params), do: GenServer.call(__MODULE__, %{test: params})

def handle_call(%{test: params}, _from, state) do
    Agent.start_link(fn -> 0 end , name: {:global, "samir_sabri"})
    {:reply, %{test: params, status: 0}, :state}
end

然后,我尝试使用iex进行测试:

CSVServer.test! 0
%{status: 0, test: 0}

process= :global.whereis_name("process_name")
#PID<0.623.0>

Process.exit(process, :kill)
true

但是,在GenServer中,未调用handle_info({:DOWN

def handle_info({:DOWN, _, :process, _pid, reason}, state) do

        Logger.info "KILLED PROCESS"
        Logger.info (Kernel.inspect(_pid))
        Logger.info (Kernel.inspect(state))
        Logger.info (Kernel.inspect(reason))
        IO.puts "KILLED PROCESS #{_pid}, #{reason}, #{state}"
    end

在我杀死链接进程后是否应该立即调用它?

0 个答案:

没有答案