<div style="font-family: Helvetica; font-size: 12px; "><div>Hi,</div><div><br></div>In most of the cases one shall not use "simple loop functions": raw process cannot participate properly in the supervision tree.</div><div style="font-family: Helvetica; font-size: 12px; "><br><div>If you need some new tricky specific model of behaving - better implement it over gen_server. </div><div>For instance supervisor is a gen_server :)</div><div><br></div><div>If you need something more low level - use 'gen' module (see how gen_fsm is implemented).</div></div>
                <div><div><br></div>--</div><div>Regards<br><div>RG ( +375 33 602 5080, UTC+3 )</div><div><br></div></div>
                 
                <p style="color: #A0A0A8;">On Friday, November 30, 2012 at 11:25 am, Vineet Naik wrote:</p>
                <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
                    <span><div><div><div>Hello,</div><div><br></div><div>I am an Erlang newbie and trying to write a simple chat bot as an</div><div>XMPP external component. I am using exmpp library and following</div><div>along these tutorials[1]</div><div><br></div><div>So far I have one module `bot_server` that uses the gen_server</div><div>interface. Inside it's `handle_info` callback, incoming messages</div><div>from various client will be received. To handle and reply to the</div><div>these messages, I am thinking of spawning a "bot" process per</div><div>client. It will stay alive as long as the client is available</div><div>ie. when the client sends "unavailable" presence, it will die. I</div><div>also need to keep a list of all the alive bot processes in the</div><div>bot_server's state.</div><div><br></div><div>My question is, would it be appropriate to implement the bot as a</div><div>gen_server too considering that it needs to handle two calls, one</div><div>for handling incoming message (asynchronous) and second for</div><div>killing itself (synchronous)?</div><div><br></div><div>In general, when should one use gen_server and when should</div><div>one write a simple loop function?</div><div><br></div><div>[1] exmpp tutorials:</div><div><a href="http://blog.process-one.net/scalable_xmpp_bots_with_erlang_and_exmpp_part_i/">http://blog.process-one.net/scalable_xmpp_bots_with_erlang_and_exmpp_part_i/</a></div><div><br></div><div>Thanks,</div><div>Vineet</div><div>_______________________________________________</div><div>erlang-questions mailing list</div><div><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a></div><div><a href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a></div></div></div></span>
                 
                 
                 
                 
                </blockquote>
                 
                <div>
                    <br>
                </div>