<div><font color="#3366ff"><font><font face="tahoma,sans-serif">Hi,</font></font></font></div><div><font color="#3366ff"><font><font face="tahoma,sans-serif"><br></font></font></font></div><div><font color="#3366ff"><font><font face="tahoma,sans-serif">I am trying to make a listener tree using gen_event behavior.</font></font></font></div>
<div><font color="#3366ff"><font><font face="tahoma,sans-serif"><br></font></font></font></div><div><font color="#3366ff"><font><font face="tahoma,sans-serif">I have a listener module, which will have an event type and a </font></font></font></div>
<div><font color="#3366ff"><font><font face="tahoma,sans-serif">list of callbacks in its state. </font></font></font><span style="font-family:tahoma,sans-serif;color:rgb(51,102,255)">It will receive event in format </span></div>
<div><span style="font-family:tahoma,sans-serif;color:rgb(51,102,255)">{EventName, Payload}, and call all the callbacks with Payload</span></div><div><span style="font-family:tahoma,sans-serif;color:rgb(51,102,255)">if EventName matches the event type it handles:</span></div>
<div><span style="font-family:tahoma,sans-serif;color:rgb(51,102,255)"><br></span></div><div><span style="font-family:tahoma,sans-serif;color:rgb(51,102,255)"><div>handle_event({EventName, Payload}, {EventName, Callbacks}) -></div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>[Callback(Payload) || Callback <- Callbacks],</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{ok, {EventName, Callbacks}};</div>
</span></div><div><span style="font-family:tahoma,sans-serif;color:rgb(51,102,255)"><br></span></div><div><span style="font-family:tahoma,sans-serif;color:rgb(51,102,255)">In another module, I have a function</span></div>
<div><span style="font-family:tahoma,sans-serif;color:rgb(51,102,255)"><br></span></div><div><span style="font-family:tahoma,sans-serif;color:rgb(51,102,255)">on(EventName, EventMgr, Callback)</span></div><div><span style="font-family:tahoma,sans-serif;color:rgb(51,102,255)"><br>
</span></div><div><font color="#3366ff" face="tahoma, sans-serif">Which allows me to add the listener callback module into a</font></div><div><font color="#3366ff" face="tahoma, sans-serif">gen_event manager EventMgr for EventName.</font></div>
<div><font color="#3366ff" face="tahoma, sans-serif"><br></font></div><div><font color="#3366ff" face="tahoma, sans-serif">The EventMgr also has other callback modules to hold other</font></div><div><font color="#3366ff" face="tahoma, sans-serif">states.</font></div>
<div><font color="#3366ff" face="tahoma, sans-serif"><br></font></div><div><font color="#3366ff" face="tahoma, sans-serif">If my Callback is like this</font></div><div><font color="#3366ff" face="tahoma, sans-serif"><br>
</font></div>
<div><font color="#3366ff" face="tahoma, sans-serif">Callback = fun(Payload) -></font></div><div><font color="#3366ff" face="tahoma, sans-serif"> io:format("About to run callback~n),</font></div><div><font color="#3366ff" face="tahoma, sans-serif"> Prop = gen_event:call(EventMgr, other_module, some_property)</font></div>
<font color="#3366ff"><font><font face="tahoma,sans-serif"><div><font color="#3366ff"><font><font face="tahoma,sans-serif"> io:format("This never runs~n")</font></font></font></div><div><font color="#3366ff"><font><font face="tahoma,sans-serif">end</font></font></font></div>
<div><font color="#3366ff"><font><font face="tahoma,sans-serif"><br></font></font></font></div><div><font color="#3366ff"><font><font face="tahoma,sans-serif">The problem is gen_event:call is not running inside the Callback.</font></font></font></div>
<div><font color="#3366ff"><font><font face="tahoma,sans-serif">I don't event see the second io:format</font></font></font></div><div><font color="#3366ff"><font><font face="tahoma,sans-serif"><br></font></font></font></div>
<div><font color="#3366ff"><font><font face="tahoma,sans-serif">To think about it, the Callback is executed inside a handle_event</font></font></font></div><div>of the EventMgr, so I guess it's not in the right scope of something?</div>
<div><br></div><div>It's also the same if inside a handle_event of some other module,</div><div>I do gen_event:call(self(), a_different_module, some_property), so</div><div>I take that this is not allowed.</div><div>
<br>
</div><div>Is there anyway to do what I want to do?</div><br clear="all"></font></font></font>Sincerely,<br><br><div><br>Son Tran-Nguyen</div>