<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: An Introduction to gen_server: &#8220;ErlyBank&#8221;</title>
	<atom:link href="http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/feed/" rel="self" type="application/rss+xml" />
	<link>http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/</link>
	<description>Linking You to Erlang</description>
	<pubDate>Tue, 06 Jan 2009 06:46:38 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: John Bender</title>
		<link>http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/#comment-1049</link>
		<dc:creator>John Bender</dc:creator>
		<pubDate>Sun, 14 Dec 2008 22:02:23 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=27#comment-1049</guid>
		<description>Awesome set of articles. They've been linked to on http://erlanguid.com, and I hope there are other avenues for people to find them. Great read, and thank you for taking the time to teach others!</description>
		<content:encoded><![CDATA[<p>Awesome set of articles. They&#8217;ve been linked to on <a href="http://erlanguid.com" rel="nofollow">http://erlanguid.com</a>, and I hope there are other avenues for people to find them. Great read, and thank you for taking the time to teach others!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Weldon</title>
		<link>http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/#comment-145</link>
		<dc:creator>David Weldon</dc:creator>
		<pubDate>Tue, 30 Sep 2008 02:29:13 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=27#comment-145</guid>
		<description>That makes perfect sense. Thanks for the fast reply Mitchell. Your articles are fantastic!</description>
		<content:encoded><![CDATA[<p>That makes perfect sense. Thanks for the fast reply Mitchell. Your articles are fantastic!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mitchell</title>
		<link>http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/#comment-141</link>
		<dc:creator>Mitchell</dc:creator>
		<pubDate>Mon, 29 Sep 2008 23:19:45 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=27#comment-141</guid>
		<description>David,

Literally, I was correct in saying that a gen_server can't handle multiple clients &lt;em&gt;concurrently&lt;/em&gt;. But normally this isn't an issue since casting is so quick (since its a one-way message). If you want a gen_server to begin processing a message and be able to send back to the caller, I would spawn off the long running process, store the &lt;span class="code inline"&gt;From&lt;/span&gt; parameter of &lt;tt&gt;gen_server:call&lt;/tt&gt; and manually use &lt;tt&gt;gen_server:reply&lt;/tt&gt; to reply via the spawned process.

To put this into a clearer example (I hope), imagine having a math server (based on gen_server) and there is a call which calculates all the primes up to &lt;tt&gt;n&lt;/tt&gt;. For certain large n, this process can take quite awhile, so instead of doing all the calculations in the math server process, I would do something like the following:

&lt;div class="code"&gt;&lt;pre&gt;
handle_call({primes, N}, From, State) -&gt;
  spawn(?MODULE, calculate_primes, [From, N]),
  {noreply, State}.

calculate_primes(From, N) -&gt;
  Primes = [],
  % Use some method of calculating prime numbers...
  gen_server:reply(From, {primes, Primes}).
&lt;/pre&gt;&lt;/div&gt;
&#160;

Hopefully the example above poses a fairly obvious solution. As you can see in handle_call, since it spawns off the calculation work, it is able to become ready to handle more calls/casts/etc. right away. Then, when the calculate_primes method ends, it explicitly sends the respond back to the caller.

Mitchell</description>
		<content:encoded><![CDATA[<p>David,</p>
<p>Literally, I was correct in saying that a gen_server can&#8217;t handle multiple clients <em>concurrently</em>. But normally this isn&#8217;t an issue since casting is so quick (since its a one-way message). If you want a gen_server to begin processing a message and be able to send back to the caller, I would spawn off the long running process, store the <span class="code inline">From</span> parameter of <tt>gen_server:call</tt> and manually use <tt>gen_server:reply</tt> to reply via the spawned process.</p>
<p>To put this into a clearer example (I hope), imagine having a math server (based on gen_server) and there is a call which calculates all the primes up to <tt>n</tt>. For certain large n, this process can take quite awhile, so instead of doing all the calculations in the math server process, I would do something like the following:</p>
<div class="code">
<pre>
handle_call({primes, N}, From, State) ->
  spawn(?MODULE, calculate_primes, [From, N]),
  {noreply, State}.

calculate_primes(From, N) ->
  Primes = [],
  % Use some method of calculating prime numbers...
  gen_server:reply(From, {primes, Primes}).
</pre>
</div>
<p>&nbsp;</p>
<p>Hopefully the example above poses a fairly obvious solution. As you can see in handle_call, since it spawns off the calculation work, it is able to become ready to handle more calls/casts/etc. right away. Then, when the calculate_primes method ends, it explicitly sends the respond back to the caller.</p>
<p>Mitchell</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Weldon</title>
		<link>http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/#comment-135</link>
		<dc:creator>David Weldon</dc:creator>
		<pubDate>Mon, 29 Sep 2008 20:19:41 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=27#comment-135</guid>
		<description>"A gen_server by itself doesn’t handle multiple clients concurrently. And although this feature would not be much harder to add..." Can you give some brief insight as to how one could accomplish this?</description>
		<content:encoded><![CDATA[<p>&#8220;A gen_server by itself doesn’t handle multiple clients concurrently. And although this feature would not be much harder to add&#8230;&#8221; Can you give some brief insight as to how one could accomplish this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Performing Real-time Upgrades to an OTP System &#124; spawn_link</title>
		<link>http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/#comment-110</link>
		<dc:creator>Performing Real-time Upgrades to an OTP System &#124; spawn_link</dc:creator>
		<pubDate>Wed, 24 Sep 2008 17:19:19 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=27#comment-110</guid>
		<description>[...] final article of the Erlang/OTP introduction series. If you haven&#8217;t already, I recommend you read the first article which lays the foundation for the application which we&#8217;ll be upgrading in addition to [...]</description>
		<content:encoded><![CDATA[<p>[...] final article of the Erlang/OTP introduction series. If you haven&#8217;t already, I recommend you read the first article which lays the foundation for the application which we&#8217;ll be upgrading in addition to [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: An Introduction to Releases with Erlybank &#124; spawn_link</title>
		<link>http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/#comment-92</link>
		<dc:creator>An Introduction to Releases with Erlybank &#124; spawn_link</dc:creator>
		<pubDate>Wed, 17 Sep 2008 15:05:22 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=27#comment-92</guid>
		<description>[...] is the sixth article in the otp introduction series. If you haven&#8217;t yet, I recommend you start with the first article which talks about gen_server and lays the foundation for our bank system. If you&#8217;re a quick [...]</description>
		<content:encoded><![CDATA[<p>[...] is the sixth article in the otp introduction series. If you haven&#8217;t yet, I recommend you start with the first article which talks about gen_server and lays the foundation for our bank system. If you&#8217;re a quick [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dew Drop - September 17, 2008 &#124; Alvin Ashcraft's Morning Dew</title>
		<link>http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/#comment-90</link>
		<dc:creator>Dew Drop - September 17, 2008 &#124; Alvin Ashcraft's Morning Dew</dc:creator>
		<pubDate>Wed, 17 Sep 2008 13:37:37 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=27#comment-90</guid>
		<description>[...] An Introduction to gen_server: &#34;ErlyBank&#34; [...]</description>
		<content:encoded><![CDATA[<p>[...] An Introduction to gen_server: &quot;ErlyBank&quot; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bundling ErlyBank as an Application &#124; spawn_link</title>
		<link>http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/#comment-81</link>
		<dc:creator>Bundling ErlyBank as an Application &#124; spawn_link</dc:creator>
		<pubDate>Mon, 15 Sep 2008 15:38:45 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=27#comment-81</guid>
		<description>[...] is the fifth article in the otp introduction series. If you haven&#8217;t yet, I recommend you start with the first article which talks about gen_server and lays the foundation for our bank system. If you&#8217;re a quick [...]</description>
		<content:encoded><![CDATA[<p>[...] is the fifth article in the otp introduction series. If you haven&#8217;t yet, I recommend you start with the first article which talks about gen_server and lays the foundation for our bank system. If you&#8217;re a quick [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Using Supervisors to Keep ErlyBank Afloat &#124; spawn_link</title>
		<link>http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/#comment-61</link>
		<dc:creator>Using Supervisors to Keep ErlyBank Afloat &#124; spawn_link</dc:creator>
		<pubDate>Sat, 13 Sep 2008 14:46:27 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=27#comment-61</guid>
		<description>[...] is the fourth article in the otp introduction series. If you haven&#8217;t yet, I recommend you start with the first article which talks about gen_server and lays the foundation for our bank system. If you are a quick [...]</description>
		<content:encoded><![CDATA[<p>[...] is the fourth article in the otp introduction series. If you haven&#8217;t yet, I recommend you start with the first article which talks about gen_server and lays the foundation for our bank system. If you are a quick [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mitchell</title>
		<link>http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/#comment-57</link>
		<dc:creator>Mitchell</dc:creator>
		<pubDate>Thu, 11 Sep 2008 06:54:42 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=27#comment-57</guid>
		<description>Hi Swaroop,

First, thank you for the kind words. Next, to answer your question, I have taken a very brief look at Disco but I haven't had enough experience using it in practice to come to a valuable conclusion about it. 

Maybe I will, but at the moment I don't have a need for disco :)</description>
		<content:encoded><![CDATA[<p>Hi Swaroop,</p>
<p>First, thank you for the kind words. Next, to answer your question, I have taken a very brief look at Disco but I haven&#8217;t had enough experience using it in practice to come to a valuable conclusion about it. </p>
<p>Maybe I will, but at the moment I don&#8217;t have a need for disco <img src='http://spawnlink.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
</channel>
</rss>
