[erlang-questions] Perform gen_event:call/3 inside Module:handle_event/2

Son Tran-Nguyen esente@REDACTED
Thu Oct 25 17:40:57 CEST 2012


Hi,

I am trying to make a listener tree using gen_event behavior.

I have a listener module, which will have an event type and a
list of callbacks in its state. It will receive event in format
{EventName, Payload}, and call all the callbacks with Payload
if EventName matches the event type it handles:

handle_event({EventName, Payload}, {EventName, Callbacks}) ->
 [Callback(Payload) || Callback <- Callbacks],
{ok, {EventName, Callbacks}};

In another module, I have a function

on(EventName, EventMgr, Callback)

Which allows me to add the listener callback module into a
gen_event manager EventMgr for EventName.

The EventMgr also has other callback modules to hold other
states.

If my Callback is like this

Callback = fun(Payload) ->
  io:format("About to run callback~n),
  Prop = gen_event:call(EventMgr, other_module, some_property)
  io:format("This never runs~n")
end

The problem is gen_event:call is not running inside the Callback.
I don't event see the second io:format

To think about it, the Callback is executed inside a handle_event
of the EventMgr, so I guess it's not in the right scope of something?

It's also the same if inside a handle_event of some other module,
I do gen_event:call(self(), a_different_module, some_property), so
I take that this is not allowed.

Is there anyway to do what I want to do?

Sincerely,


Son Tran-Nguyen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121025/70453c77/attachment.htm>


More information about the erlang-questions mailing list