[erlang-questions] Sending messages to gen_event manager

Ben Hood 0x6e6562@REDACTED
Sat Jul 21 15:57:55 CEST 2007


Hi,

I'm trying to use the gen_event behaviour to manage some event driven
logic and the process seems to be pretty straight forward.

1. As a alternative to the notify/2 call, if if store the Pid of the
event manager when it is started, i.e.

{ok, Pid } = gen_event:start_link( {local, man} ).

can I just implement a handle_info/2 callback on my handler and then I
can send it events as such:

Pid ! { my_message }

Are these approaches equivalent apart from the fact that one is a
by-name invocation and the other is a by-pid invocation?

Does the by-pid invocation have any implications on the state,
lifecycle or supervision tree of the handler?

2. Say I have multiple event handlers that need to respond differently
to different types of events, it is a sounder design to add multiple
callbacks to one event manager and then pattern match on the
handle_event/2 callback, or does it make more sense to just create a
new event manager for each event type?

Naively I would go for the latter option, but this may create lots of
event manager processes. Is this problematic?

Thx,

Ben



More information about the erlang-questions mailing list