我尝试将消息转发给gen_server:
gen_server:cast({global, ID}, {watchers}).
处理程序是:
handle_cast({watchers}, State) ->
case State#table_state.watchers of
[] ->
{reply, no_watchers, State};
_ ->
{reply, State#table_state.watchers, State}
end;
但是当我执行gen_server:cast
时,gen_server以错误终止:
=ERROR REPORT==== 29-Apr-2011::18:26:07 ===
** Generic server 1 terminating
** Last message in was {'$gen_cast',{watchers}}
** When Server state == {table_state,1,"1",11,[]}
** Reason for termination ==
** {bad_return_value,{reply, no_watchers, {table_state,3,"3",11,[]}}}
为什么我会获得bad_return_value
?
答案 0 :(得分:12)
您无法使用演员表回复(请参阅gen_server
documentation)。这是构建异步消息而不是使用call的全部要点。
在您的情况下,您想要回复,因此请改用gen_server:call/2
。