SV: Trouble with gen_server

Mark Lee <>
Tue Mar 28 15:50:11 CEST 2006


O nTue, Mar 28, 2006 at 03:31:38PM +0200, Lennart Öhman wrote:
> Hi, if you include a code example it becomes easier to help :-)
>  
> /Lennart


Ok, as simple as I can get.

1> test:start_link().
{ok,<0.33.0>}
2> test:test().
** exited: {timeout,{gen_server,call,[test,test]}} **
3> test:test().
** exited: {noproc,{gen_server,call,[test,test]}} **

or

1> test:start_link().
{ok,<0.33.0>}
2> oops().

=ERROR REPORT==== 28-Mar-2006::14:45:20 ===
Error in process <0.31.0> with exit value:
{undef,[{shell_default,oops,[]},{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}

** exited: {undef,[{shell_default,oops,[]},
                   {erl_eval,do_apply,5},
                   {shell,exprs,6},
                   {shell,eval_loop,3}]} **
3> test:test().
** exited: {noproc,{gen_server,call,[test,test]}} **

Here's the code:


-export([start_link/0]).

-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
		 terminate/2, code_change/3, test/0]).

-record(state, {}).

-define(SERVER, ?MODULE).

start_link() ->
	gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).

init([]) ->
	{ok, #state{}}.

handle_call(test, _From, State) ->
	{noreply, State, 3000};
handle_call(_Request, _From, State) ->
	Reply = ok,
	{reply, Reply, State}.

handle_cast(_Msg, State) ->
	{noreply, State}.

handle_info(_Info, State) ->
	{noreply, State}.

terminate(_Reason, _State) ->
	ok.

code_change(_OldVsn, State, _Extra) ->
	{ok, State}.

test() ->
	gen_server:call(test, test).



More information about the erlang-questions mailing list