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

Son Tran-Nguyen <>
Thu Oct 25 19:11:50 CEST 2012


Hi

On Thu, Oct 25, 2012 at 11:40 AM, Dmitry Kolesnikov
<>wrote:

> Hello,
>
> you could achieve dynamic behavior through add_handler/add_sup_handler and
> delete_handler.
> The major point here you are re-using existed OTP function.
>

I think you and I have a different understanding of the dynamic behavior I
mentioned. By using just one module with the support of callbacks list, I
could handle the event without knowing the handler's behavior beforehand.
If I use add_handler/add_sup_handler, it will add a lot of callback module
into the event manager and the number of handlers is equal to the number of
callbacks, even when some callbacks are for the same event type. If I use
one module with dynamic callbacks, the number of handlers is equal to the
number of event types, and I can support more.


>
> The requirement to accure all of the state of another event handler might
> be challenging.
> I believe you need to
>  a) either execute callback in dedicated process spawn(fun() ->
> Callback(Payload) end)
>

I am actually going this route.


>  b) re-factor your listener concept where event handlers independent. I
> would propose to follow-up this way.
>

I don't think it matters whether event handlers are independent. Event
within an even handler, I cannot do gen_event:call to get the state of a
different event handler.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121025/28853354/attachment.html>


More information about the erlang-questions mailing list