<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Ajax, javascript and threads : the final truth</title>
	<atom:link href="http://ajaxian.com/archives/ajax-javascript-and-threads-the-final-truth/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/ajax-javascript-and-threads-the-final-truth</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Fri, 19 Mar 2010 22:31:23 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: ireshagun</title>
		<link>http://ajaxian.com/archives/ajax-javascript-and-threads-the-final-truth/comment-page-1#comment-277415</link>
		<dc:creator>ireshagun</dc:creator>
		<pubDate>Fri, 18 Dec 2009 01:25:34 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2489#comment-277415</guid>
		<description>There is a legitimate way of multi-threading in java without all these artificial constructs.

http://codediaries.blogspot.com/2009/12/real-javascript-multithreading-using.html</description>
		<content:encoded><![CDATA[<p>There is a legitimate way of multi-threading in java without all these artificial constructs.</p>
<p><a href="http://codediaries.blogspot.com/2009/12/real-javascript-multithreading-using.html" rel="nofollow">http://codediaries.blogspot.com/2009/12/real-javascript-multithreading-using.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: joseanpg</title>
		<link>http://ajaxian.com/archives/ajax-javascript-and-threads-the-final-truth/comment-page-1#comment-253341</link>
		<dc:creator>joseanpg</dc:creator>
		<pubDate>Tue, 31 Jul 2007 00:59:27 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2489#comment-253341</guid>
		<description>He probado el cÃ³digo de ix en FF e IE y el comportamiento es el esperado:  la ejecuciÃ³n de la funciÃ³n pasada en el setTimeout sÃ³lo ocurre cuando el bloque de cÃ³digo que la &quot;lanza&quot; ha terminado. Es decir, los alert no permiten que los asincronos &quot;expropien&quot; al bloque de cÃ³digo que ejecuto el alert.

var nullable = null;
var loop = 500000;
var timeOut = setTimeout(function(){alert(nullable)}, 1);
for(var i = 0;i </description>
		<content:encoded><![CDATA[<p>He probado el cÃ³digo de ix en FF e IE y el comportamiento es el esperado:  la ejecuciÃ³n de la funciÃ³n pasada en el setTimeout sÃ³lo ocurre cuando el bloque de cÃ³digo que la &#8220;lanza&#8221; ha terminado. Es decir, los alert no permiten que los asincronos &#8220;expropien&#8221; al bloque de cÃ³digo que ejecuto el alert.</p>
<p>var nullable = null;<br />
var loop = 500000;<br />
var timeOut = setTimeout(function(){alert(nullable)}, 1);<br />
for(var i = 0;i</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Couvreur</title>
		<link>http://ajaxian.com/archives/ajax-javascript-and-threads-the-final-truth/comment-page-1#comment-251576</link>
		<dc:creator>Julien Couvreur</dc:creator>
		<pubDate>Thu, 14 Jun 2007 22:23:06 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2489#comment-251576</guid>
		<description>You can implement a form of multi-threading in javascript, by having your code voluntarily yield execution and a scheduler object to give each thread some time.
Neil Mix wrote a library to allow this in javascript. I blogged about it at: http://blog.monstuff.com/archives/000315.html</description>
		<content:encoded><![CDATA[<p>You can implement a form of multi-threading in javascript, by having your code voluntarily yield execution and a scheduler object to give each thread some time.<br />
Neil Mix wrote a library to allow this in javascript. I blogged about it at: <a href="http://blog.monstuff.com/archives/000315.html" rel="nofollow">http://blog.monstuff.com/archives/000315.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrea Giammarchi</title>
		<link>http://ajaxian.com/archives/ajax-javascript-and-threads-the-final-truth/comment-page-1#comment-251574</link>
		<dc:creator>Andrea Giammarchi</dc:creator>
		<pubDate>Thu, 14 Jun 2007 21:20:50 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2489#comment-251574</guid>
		<description>Kris, it&#039;s not a &quot;so perfect&quot; answer because if You generate a modal event inside long execution code (i.e. alert(&quot;go on, async queue&quot;);) ajax, as intervals, starts while function execution is &quot;blocked&quot; :-)

&lt;code&gt;for(var
	nullable = null,
	i = 0,
	loop = 500000,
	timeOut = setTimeout(function(){alert(nullable)}, 1);
	i &lt; loop; i++
) {
	if(i + 1 === loop) {
		// comment this alert to read Hello World
		alert(&quot;nullable not yet setted&quot;);
		
		nullable = &quot;Hello World&quot;;
	}
};&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Kris, it&#8217;s not a &#8220;so perfect&#8221; answer because if You generate a modal event inside long execution code (i.e. alert(&#8221;go on, async queue&#8221;);) ajax, as intervals, starts while function execution is &#8220;blocked&#8221; :-)</p>
<p><code>for(var<br />
	nullable = null,<br />
	i = 0,<br />
	loop = 500000,<br />
	timeOut = setTimeout(function(){alert(nullable)}, 1);<br />
	i &lt; loop; i++<br />
) {<br />
	if(i + 1 === loop) {<br />
		// comment this alert to read Hello World<br />
		alert("nullable not yet setted");</p>
<p>		nullable = "Hello World";<br />
	}<br />
};</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ix</title>
		<link>http://ajaxian.com/archives/ajax-javascript-and-threads-the-final-truth/comment-page-1#comment-251571</link>
		<dc:creator>ix</dc:creator>
		<pubDate>Thu, 14 Jun 2007 19:03:39 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2489#comment-251571</guid>
		<description>tim: JS isnt tail recursive? also have you considered using DOM synthetic events as a message passing idiom instead building up some tower of babel in callbacks..</description>
		<content:encoded><![CDATA[<p>tim: JS isnt tail recursive? also have you considered using DOM synthetic events as a message passing idiom instead building up some tower of babel in callbacks..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kris Zyp</title>
		<link>http://ajaxian.com/archives/ajax-javascript-and-threads-the-final-truth/comment-page-1#comment-251566</link>
		<dc:creator>Kris Zyp</dc:creator>
		<pubDate>Thu, 14 Jun 2007 17:58:46 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2489#comment-251566</guid>
		<description>The browser JS engine has a queue that it uses to process events (ajax responses, and setTimeouts count as events here). The queue just processes one event after another, one at a time. Each time an event is finished (which may take a lot of time as you observed), it will execute the next one. That is why you observe this behavior.</description>
		<content:encoded><![CDATA[<p>The browser JS engine has a queue that it uses to process events (ajax responses, and setTimeouts count as events here). The queue just processes one event after another, one at a time. Each time an event is finished (which may take a lot of time as you observed), it will execute the next one. That is why you observe this behavior.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrea Giammarchi</title>
		<link>http://ajaxian.com/archives/ajax-javascript-and-threads-the-final-truth/comment-page-1#comment-251563</link>
		<dc:creator>Andrea Giammarchi</dc:creator>
		<pubDate>Thu, 14 Jun 2007 15:12:53 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2489#comment-251563</guid>
		<description>... oops ... 

for(var 
	nullable = null,
	i = 0,
	loop = 500000,
	timeOut = setTimeout(function(){alert(nullable)}, 1);
	i &lt; loop; i++
) {
	if(i + 1 === loop)
		nullable = &quot;Hello World&quot;;
};</description>
		<content:encoded><![CDATA[<p>&#8230; oops &#8230; </p>
<p>for(var<br />
	nullable = null,<br />
	i = 0,<br />
	loop = 500000,<br />
	timeOut = setTimeout(function(){alert(nullable)}, 1);<br />
	i &lt; loop; i++<br />
) {<br />
	if(i + 1 === loop)<br />
		nullable = &#8220;Hello World&#8221;;<br />
};</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrea Giammarchi</title>
		<link>http://ajaxian.com/archives/ajax-javascript-and-threads-the-final-truth/comment-page-1#comment-251562</link>
		<dc:creator>Andrea Giammarchi</dc:creator>
		<pubDate>Thu, 14 Jun 2007 15:12:17 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2489#comment-251562</guid>
		<description>c&#039;mon guys ...

for(var 
	nullable = null,
	i = 0,
	loop = 500000,
	timeOut = setTimeout(function(){alert(nullable)}, 1);
	i </description>
		<content:encoded><![CDATA[<p>c&#8217;mon guys &#8230;</p>
<p>for(var<br />
	nullable = null,<br />
	i = 0,<br />
	loop = 500000,<br />
	timeOut = setTimeout(function(){alert(nullable)}, 1);<br />
	i</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carlos Aguayo</title>
		<link>http://ajaxian.com/archives/ajax-javascript-and-threads-the-final-truth/comment-page-1#comment-251561</link>
		<dc:creator>Carlos Aguayo</dc:creator>
		<pubDate>Thu, 14 Jun 2007 14:38:28 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2489#comment-251561</guid>
		<description>Brendan Eich wrote an article about threads a couple of months ago...
http://weblogs.mozillazine.org/roadmap/archives/2007/02/threads_suck.html</description>
		<content:encoded><![CDATA[<p>Brendan Eich wrote an article about threads a couple of months ago&#8230;<br />
<a href="http://weblogs.mozillazine.org/roadmap/archives/2007/02/threads_suck.html" rel="nofollow">http://weblogs.mozillazine.org/roadmap/archives/2007/02/threads_suck.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Al Jourgenson</title>
		<link>http://ajaxian.com/archives/ajax-javascript-and-threads-the-final-truth/comment-page-1#comment-251556</link>
		<dc:creator>Al Jourgenson</dc:creator>
		<pubDate>Thu, 14 Jun 2007 13:09:01 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2489#comment-251556</guid>
		<description>Just a minor typo...

&quot;a long running function that fires of an XHR request&quot;

should be:

&quot;a long running function that fires off an XHR request&quot;

tx</description>
		<content:encoded><![CDATA[<p>Just a minor typo&#8230;</p>
<p>&#8220;a long running function that fires of an XHR request&#8221;</p>
<p>should be:</p>
<p>&#8220;a long running function that fires off an XHR request&#8221;</p>
<p>tx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Cooijmans</title>
		<link>http://ajaxian.com/archives/ajax-javascript-and-threads-the-final-truth/comment-page-1#comment-251551</link>
		<dc:creator>Tim Cooijmans</dc:creator>
		<pubDate>Thu, 14 Jun 2007 11:47:00 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2489#comment-251551</guid>
		<description>Is this really news to anyone?  If you hog the CPU, it&#039;ll block asynchronous stuff, such as XMLHttpRequests and setTimeouts.  This is also quite consistent across browsers and platforms.  (The alert() just temporarily stops your scripts from hogging the CPU until you dismiss the dialog.)

As for the breaking up of functions, I&#039;m personally getting into the habit of using callbacks for everything:

function foo () {
  // does stuff...

  // calls another function
  sleep(10, function () {
    // rest of a goes on here after 10 seconds
  });
}

function sleep (secs, callback) {
  // sleep returns by calling a&#039;s callback
  setTimeout(callback, secs * 1000);
}

This way, it doesn&#039;t matter if a function does synchronous or asynchronous stuff.  You give every function a callback and it will return using that callback.  The callback is kind of a continuation.

One problem is that this quickly builds up a huge call stack.  You can get rid of the call stack by calling a callback with setTimeout.</description>
		<content:encoded><![CDATA[<p>Is this really news to anyone?  If you hog the CPU, it&#8217;ll block asynchronous stuff, such as XMLHttpRequests and setTimeouts.  This is also quite consistent across browsers and platforms.  (The alert() just temporarily stops your scripts from hogging the CPU until you dismiss the dialog.)</p>
<p>As for the breaking up of functions, I&#8217;m personally getting into the habit of using callbacks for everything:</p>
<p>function foo () {<br />
  // does stuff&#8230;</p>
<p>  // calls another function<br />
  sleep(10, function () {<br />
    // rest of a goes on here after 10 seconds<br />
  });<br />
}</p>
<p>function sleep (secs, callback) {<br />
  // sleep returns by calling a&#8217;s callback<br />
  setTimeout(callback, secs * 1000);<br />
}</p>
<p>This way, it doesn&#8217;t matter if a function does synchronous or asynchronous stuff.  You give every function a callback and it will return using that callback.  The callback is kind of a continuation.</p>
<p>One problem is that this quickly builds up a huge call stack.  You can get rid of the call stack by calling a callback with setTimeout.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
