优雅地终止 Erlang 服务器或 fsm?
我有一个具有 gen_fsm 行为的模块。 现在,我通过在适当的状态/消息中返回标准 {stop, Reason, State} 来终止它。
它似乎正确终止,但在运行时被认为是错误。
这是正常的吗? 有没有办法停止 fsm 进程而不将其视为错误?
I have a module that has the behavior of gen_fsm. Right now I am terminating it by returning the standard {stop, Reason, State} in an appropriate state/message.
It seems to terminate correctly, but it's considered an error during runtime.
Is this normal? Is there a way to stop the fsm process without it being considered an error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
返回值是 {stop,Reason,StateData} 而不是 {stop,StateName,StateData}。
如果原因不是正常或关闭,则会生成错误报告。 对于服务器的正常退出,请使用正常,当服务器被其主管要求退出时,使用关闭。
(现在进行编辑,已添加错误详细信息。)
gen_fsm
正在调用client_fsm:terminate(normal, displayed, {state,#Port<0.144>,12345,"Bob"})< /code>
这会导致 function_clause 异常(该函数存在,但没有子句可以与这些参数匹配)。 如果您更改
client_fsm:terminate/3
以使该调用成功,则错误应该消失。The return value is {stop,Reason,StateData} not {stop,StateName,StateData}.
An error report is generated if Reason is something other than normal or shutdown. For a normal exit of your server use normal, shutdown is used when the server is asked to exit by its supervisor.
(Edit now that error details have been added.)
gen_fsm
is callingclient_fsm:terminate(normal, loggedin, {state,#Port<0.144>,12345,"Bob"})
which is leading to a function_clause exception (the function exists but no clause can be matched against those arguments). If you change
client_fsm:terminate/3
so that that call succeeds the error should go away.