[erlang-questions] Pratical solutions for selective send (was: gen_event handler question)

Per Melin <>
Wed May 13 19:49:33 CEST 2009

Davide Marquês:
> Ahoy! :)
> On Wed, Apr 29, 2009 at 9:33 AM, Camille Troillard <>
> wrote:
>> On Wed, Apr 29, 2009 at 10:17 AM, Robert Raschke <>
>> wrote:
>>> > I would like to know if it is possible to write an event handler that
>>> > would
>>> > receive only certain notifications based on a simple criteria.
>>> You could use a catch all like handle_event(_, State)-> at the end of
>>> your handlers? Not sure if that's the recommended way though.
>> Yes, I thought about this, hehe.
>> But then all the handlers would receive notifications and should decide
>> themselves wether or not they should process the message, which is not good.
>>  It looks like a design issue on my side, oh well …  maybe this is not the
>> "erlang" way to do it …
>> Cam
> After reading this I'm wondering... what's the current "erlang way" of doing
> selective sends?
> Where by "selective send" I mean:
>  - a client process sends a "message filter" to a server process;
>  - when an event occurs the server checks the client's "message filter" to
> determine if a notification should be sent.

I don't understand what's wrong with gen_event in this case? An event
handler is not its own process. It's just a callback module. There is
only one process and that's the event manager. Using a catch-all
handle_event/2 should be an extremely cheap way to disregard events
you're not interested in. Not that I have run any benchmarks.

More information about the erlang-questions mailing list