There are many things wrong with this code. Here goes...
The reason the start_link
function is called that is because it starts the process and links to it. Your stop
function should just be called stop
.
The documentation for gen_server:call/2,3
shows up two problems with this code:
- You don't need the
{local, Name}
form with gen_server:call
. You only need it when calling gen_server:start_link
(and only then if you want a registered name for your process). For calling local names, just use Name
. Or the process ID.
- There isn't a variant of the function with arity 4 (i.e. 4 parameters). The 3-arity variant takes a timeout. You probably want the 2-arity one.
I suspect that you're trying to specify an arbitrary function in gen_server:call
(i.e. you want to call the terminate
function). That's not how this works.
gen_server:call(NameOrPid, Request)
results in a call to handle_call(Request, From, State)
. See the documentation.
In that function, you can match the request and do the appropriate thing. Something like this:
handle_call(frob, _From, State) ->
% do whatever 'frob' means.
{reply, ok, NewState};
(that ;
might be a .
, depending on whether this is the final handle_call
clause).
If you really want the server to stop, you should just do the following:
handle_call(terminate, _From, State) ->
{stop, meh, State}.
That will result in a call to terminate
.
Oh, and if you're only just learning Erlang, you probably don't want to be running dialyzer until you've got a bit more experience. It's a bit ... tricky ... for the uninitiated. Though it did find this mistake, which was nice.