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

Dmitry Kolesnikov dmkolesnikov@REDACTED
Thu Oct 25 17:56:02 CEST 2012


Hello,

In the nutshell, you are having deadlock at gen_event:call within event manager.

Could you please elaborate
 * why do you have a list of callbacks within an event manager? Event Manager manages a list of event handlers for you?
 * why do you try to call event handler?

I think in your case, a gen_server is required so that event_handler catches an event and passes it to gen_server that does a magical job for you.

- Dmitry

On Oct 25, 2012, at 6:40 PM, Son Tran-Nguyen wrote:

> 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
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121025/052fb707/attachment.htm>


More information about the erlang-questions mailing list