作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在从 GenServer 中的句柄信息功能调用 elixir genserver 以添加电话号码获取表单客户端。但是一旦调用了handle_call,所有者进程就会崩溃[超时]。请帮忙。
全局创建一个 ETS 以在调用任何下述函数之前插入值。
def handle_info(message, state) do
{a,b} = message
phonenumber = b[:body]
add phonenumber
{:noreply, state}
end
def add(phonenumber) do
GenServer.call(__MODULE__, {:add, phonenumber})
end
def handle_call({:add, phonenumber}, from, state) do
:ets.insert(:access_table, {:details, phonenumber})
reply = {:ok, "Added #{phonenumber} to profile"}
new_state = [{username} | state]
{:reply, reply , new_state}
end
** When Server state == []
** Reason for termination ==
** {timeout,{gen_server,call,['Elixir.Bankrecord',{add,"346534543534"},5000]}}
** (EXIT from #PID<0.150.0>) exited in: :gen_server.call(Bankrecord, {:add, '346534543534'}, 5000)
** (EXIT) time out
最佳答案
你不能在通话中给自己打电话,就像在你的 handle_info 调用 add
它在您的 gen_server 上执行回调。由于所有操作都在 gen_server 中按顺序发生,因此您最终会阻止自己。解决方案应该是使用简单的私有(private) add
模块上的功能并具有handle_info
和 handle_call({:add
委托(delegate)给它。
def add(phonenumber) do
GenServer.call(__MODULE__, {:add, phonenumber})
end
def handle_info({_, message}, state) do
add_number message[:body]
{:noreply, state}
end
def handle_call({:add, phonenumber}, from, state) do
add_number phonenumber
{:reply, {:ok, "Added #{phonenumber} to profile"} , [{username} | state]}
end
defp add_number(phonenumber) do
:ets.insert(:access_table, {:details, phonenumber})
end
关于elixir - “handle_call”超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25194994/
我正在从 GenServer 中的句柄信息功能调用 elixir genserver 以添加电话号码获取表单客户端。但是一旦调用了handle_call,所有者进程就会崩溃[超时]。请帮忙。 全局创建
我有一个关于监控/链接进程死亡时间的问题,我想不出如何在实践中测试它。这是我担心的情况。 假设我有一个名为 master 和 slave 的进程。 master 将 trap_exit 设置为 tru
使用以下方式启动服务器: erlc server.erl ; erl -eval 'server:start()' 在另一个终端: telnet localhost 3547 可以成功建立连接,但是几
我是一名优秀的程序员,十分优秀!