erlang 我试图退出,但得到一个异常错误参数,称为exit(undefined,kill)

5hcedyr0  于 2022-12-08  发布在  Erlang
关注(0)|答案(2)|浏览(161)

我试图写一个函数来终止我的程序。它叫做quitChat。但是当我调用函数messenger:quitChat()时,我得到了这个错误。

** exception error: bad argument
    in function  exit/2
        called as exit(undefined,kill)
    in call from messenger:quitChat/0 (messenger.erl, line 26)

到目前为止,我使用的是以下代码:

-module(messenger).
-export([start_server/0, server/1, logon/1, logoff/0, message/2, client/2,
requestChat/1, quitChat/0]).

server_node() ->
    messenger@timberlake.

server(User_List) ->
    receive
        {From, logon, Name} ->
            New_User_List = server_logon(From, Name, User_List),
            server(New_User_List);
        {From, logoff} ->
            New_User_List = server_logoff(From, User_List),
            server(New_User_List);
        {From, message_to, To, Message} ->
            server_transfer(From, To, Message, User_List),
            io:format("list is now: ~p~n", [User_List]),
            server(User_List)
    end.

start_server() ->
    register(messenger, spawn(messenger, server, [[]])).

quitChat() ->
    exit(whereis(messenger), kill).
iovurdzv

iovurdzv1#

使用erlang:halt/0,1
文件

vjhs03f7

vjhs03f72#

按以下方式更改您的quitChat:

quitChat() ->
   case whereis(messenger) of
      undefined -> ok; % No registered process with name messenger
      Pid -> exit(Pid, kill)
   end.

相关问题