Note that there are some explanatory texts on larger screens.

plurals
  1. POExtend gen_event behavior in Erlang
    primarykey
    data
    text
    <p>I'm writing an event manager that will take a lot of different event handlers. This event manager will be notified with a lot of different events. Each handler only handle certain events, and ignore the rest. Each handler can also trigger certain other events based on situation.</p> <p>For example, first handler to handle <code>Event1</code></p> <pre class="lang-erl prettyprint-override"><code>-module (first_handler). -behavior (gen_event). ... handle_event(Event1, State) -&gt; {ok, State}; handle_event(_, State) -&gt; {ok, State}. </code></pre> <p>Second handler to handle <code>Event2</code></p> <pre class="lang-erl prettyprint-override"><code>-module (second_handler). -behavior (gen_event). ... handle_event(Event2, State) -&gt; gen_event:notify(self(), Event1), {ok, State}; handle_event(_, State) -&gt; {ok, State}. </code></pre> <p>The event triggering can be done by calling <code>gen_event:notify(self(), NewEvent)</code> within a <code>handle_event</code> of the handler, but I would rather abstract and export that out so that it can be called from the event manager.</p> <p>Since pattern matching and ignoring events and triggering events are common to all the handlers, is there anyway I can extend <code>gen_event</code> behavior to provide those as built-ins?</p> <p>I'll start with the default way to create a custom behavior:</p> <pre class="lang-erl prettyprint-override"><code>-module (gen_new_event). -behaviour (gen_event). behaviour_info(Type) -&gt; gen_event:behaviour_info(Type). </code></pre> <p>I'm not sure what to do next.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload