[erlang-questions] gen_event help

Fernando Benavides fernando.benavides@REDACTED
Thu Jan 27 19:26:19 CET 2011


Just a guess (i.e. not actually tested on console) but... this clause
may match first...

> handle_event(_Event, State) ->
>     {ok, State};

...so nothing is shown on console.

Cheers.

On Fri, 2011-01-28 at 00:08 +0600, Alexander Kuleshov wrote:

> Hello,
> 
> I try to write simple gen_event applcation in erlang.
> 
> My code:
> 
> -module(test).
> -behavior(gen_event).
> 
> -export([notify/0]).
> 
> %% API
> -export([start_link/0, add_handler/0, stop/0]).
> 
> %% gen_event callbacks
> -export([init/1, handle_event/2, handle_call/2,
>      handle_info/2, terminate/2, code_change/3]).
> 
> -define(SERVER, ?MODULE).
> 
> start_link() ->
>     gen_event:start_link({local, ?SERVER}).
> 
> add_handler() ->
>     gen_event:add_handler(?SERVER, ?MODULE, []).
> 
> stop() ->
>     gen_event:stop(?MODULE).
> 
> init([]) ->
>     %add_handler(),
>     {ok, null}.
> 
> handle_event(_Event, State) ->
>     {ok, State};
> handle_event({test}, State) ->
>     io:format("Test"),
>     {ok, State}.
> 
> handle_call(_Request, State) ->
>     Reply = ok,
>     {ok, Reply, State}.
> 
> handle_info(_Info, State) ->
>     {ok, State}.
> 
> terminate(_Reason, _State) ->
>     ok.
> 
> code_change(_OldVsn, State, _Extra) ->
>     {ok, State}.
> 
> notify() ->
>     gen_event:notify(?SERVER, {test}).
> When i try notify i expect that function handle_event({test}, State)
> execute but nothing occurs. Why? What's wrong?
> 
> And where i can see simple example of gen_event?
> 
> Thank you.
> 
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
> 




More information about the erlang-questions mailing list