<?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: Synchronous v. Asynchronous</title>
	<atom:link href="http://www.yuiblog.com/blog/index.php/2006/04/04/synchronous-v-asynchronous/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/</link>
	<description>The official blog of the YUI Project.</description>
	<lastBuildDate>Thu, 09 Feb 2012 01:46:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
	<item>
		<title>By: Browser Hell on Blackberry Devices @ GQAdonis</title>
		<link>http://www.yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/comment-page-1/#comment-586743</link>
		<dc:creator>Browser Hell on Blackberry Devices @ GQAdonis</dc:creator>
		<pubDate>Mon, 30 Nov 2009 00:56:46 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-586743</guid>
		<description>[...] method instead of the preferred asynchronous method for web application development. This blog entry from the Yahoo! User Interface Blog makes this very clear, and it is even more so for mobile web [...]</description>
		<content:encoded><![CDATA[<p>[...] method instead of the preferred asynchronous method for web application development. This blog entry from the Yahoo! User Interface Blog makes this very clear, and it is even more so for mobile web [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pppjunk</title>
		<link>http://www.yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/comment-page-1/#comment-525125</link>
		<dc:creator>pppjunk</dc:creator>
		<pubDate>Sat, 29 Nov 2008 22:27:08 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-525125</guid>
		<description>Very simple code to illustrate my rant above.
Automatically reorders xmlhttp responses.
Put files on some server with PHP and go there. 
Have a nice day ;)

http://home.peufeu.com/posts/xhreorder.rar

Oooooo by the way it only works in Opera cause that&#039;s what I had on hand...</description>
		<content:encoded><![CDATA[<p>Very simple code to illustrate my rant above.<br />
Automatically reorders xmlhttp responses.<br />
Put files on some server with PHP and go there.<br />
Have a nice day ;)</p>
<p><a href="http://home.peufeu.com/posts/xhreorder.rar" rel="nofollow">http://home.peufeu.com/posts/xhreorder.rar</a></p>
<p>Oooooo by the way it only works in Opera cause that&#8217;s what I had on hand&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pppjunk</title>
		<link>http://www.yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/comment-page-1/#comment-524768</link>
		<dc:creator>pppjunk</dc:creator>
		<pubDate>Fri, 28 Nov 2008 22:47:29 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-524768</guid>
		<description>lol, Crockford speaks the truth, and 10 pages of complaints ensue.

I wrote a bittorrent tracker in Python, using an asynchronous select/poll model ala lighttpd. It uses all the tricks in the book, including deferred execution of closures, deferred execution of SQL queries via thread pool, generators as asynchronous fake threads, deferred zero-overhead firewall checks, and it can reload its own code without restarting. Number of concurrently opened sockets is limited only by the OS and it could handle about 1000 HTTP hits per second on my old pentium-m laptop. Since then (about 2 years ago) it has never crashed. This code could be called complex. Not &quot;very&quot; complex though.

Anyway back to xmlhttp :

var seq_counter = a global sequence counter.
var pending = an array of pending xmlhttp requests.

When sending a request, tag it with seq_counter, and increment seq_counter. Store the request in the &quot;pending&quot; array. Perhaps init a timeout to kill it if it takes too long, that&#039;s up to you.

When you get a response, look in the pending requests array. Scan it in order of sequence number. 

Process all responses received, popping them out of the array, until you find an unanswered request. If this happens, stop processing. The processing will resume from this point when/if the response is received, or the timeout kills it.

This is pretty simple and it guarantees that all responses will be processed in the same order as the requests.</description>
		<content:encoded><![CDATA[<p>lol, Crockford speaks the truth, and 10 pages of complaints ensue.</p>
<p>I wrote a bittorrent tracker in Python, using an asynchronous select/poll model ala lighttpd. It uses all the tricks in the book, including deferred execution of closures, deferred execution of SQL queries via thread pool, generators as asynchronous fake threads, deferred zero-overhead firewall checks, and it can reload its own code without restarting. Number of concurrently opened sockets is limited only by the OS and it could handle about 1000 HTTP hits per second on my old pentium-m laptop. Since then (about 2 years ago) it has never crashed. This code could be called complex. Not &#8220;very&#8221; complex though.</p>
<p>Anyway back to xmlhttp :</p>
<p>var seq_counter = a global sequence counter.<br />
var pending = an array of pending xmlhttp requests.</p>
<p>When sending a request, tag it with seq_counter, and increment seq_counter. Store the request in the &#8220;pending&#8221; array. Perhaps init a timeout to kill it if it takes too long, that&#8217;s up to you.</p>
<p>When you get a response, look in the pending requests array. Scan it in order of sequence number. </p>
<p>Process all responses received, popping them out of the array, until you find an unanswered request. If this happens, stop processing. The processing will resume from this point when/if the response is received, or the timeout kills it.</p>
<p>This is pretty simple and it guarantees that all responses will be processed in the same order as the requests.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bundled and Ordered Asynchronous AJAX</title>
		<link>http://www.yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/comment-page-1/#comment-479336</link>
		<dc:creator>Bundled and Ordered Asynchronous AJAX</dc:creator>
		<pubDate>Sat, 27 Sep 2008 06:02:53 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-479336</guid>
		<description>[...] synchronous ajax calls? Problem solved, right? Unfortunately, it&#8217;s not that simple - from the YUI blog: XMLHttpRequest can operate synchronously or asynchronously. Many people prefer to use it [...]</description>
		<content:encoded><![CDATA[<p>[...] synchronous ajax calls? Problem solved, right? Unfortunately, it&#8217;s not that simple &#8211; from the YUI blog: XMLHttpRequest can operate synchronously or asynchronously. Many people prefer to use it [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glen</title>
		<link>http://www.yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/comment-page-1/#comment-356333</link>
		<dc:creator>Glen</dc:creator>
		<pubDate>Tue, 22 Apr 2008 17:04:02 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-356333</guid>
		<description>Here&#039;s my synchronous use case:  Before I respond to any of my 50 possible ajax gestures that depend on the user being logged in, I need to verify that the user is, in fact, still logged in - that there hasn&#039;t been a session time-out.  If the session is timed out, and I no longer know who&#039;s logged in, I need to redirect to a log-in page (or some such action); otherwise, I proceed to fulfill the request for the logged in user. 

I do this with a simple javascript call, separate from the ajax call - I don&#039;t modify all my ajax request handlers to do their own checking for member login, and their own event handling (in the success function) if the member is not logged in.

I currently have a home-grown synchronous ajax call to check for logged-in-ness that I use before initiating the specific ajax action.  I was hoping to drop the home-grown stuff and just use YUI - but it appears I can&#039;t, since YUI doesn&#039;t support synchonous calls.  Is there some better YUI way to handle this use case?</description>
		<content:encoded><![CDATA[<p>Here&#8217;s my synchronous use case:  Before I respond to any of my 50 possible ajax gestures that depend on the user being logged in, I need to verify that the user is, in fact, still logged in &#8211; that there hasn&#8217;t been a session time-out.  If the session is timed out, and I no longer know who&#8217;s logged in, I need to redirect to a log-in page (or some such action); otherwise, I proceed to fulfill the request for the logged in user. </p>
<p>I do this with a simple javascript call, separate from the ajax call &#8211; I don&#8217;t modify all my ajax request handlers to do their own checking for member login, and their own event handling (in the success function) if the member is not logged in.</p>
<p>I currently have a home-grown synchronous ajax call to check for logged-in-ness that I use before initiating the specific ajax action.  I was hoping to drop the home-grown stuff and just use YUI &#8211; but it appears I can&#8217;t, since YUI doesn&#8217;t support synchonous calls.  Is there some better YUI way to handle this use case?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: feechka-no</title>
		<link>http://www.yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/comment-page-1/#comment-309906</link>
		<dc:creator>feechka-no</dc:creator>
		<pubDate>Thu, 21 Feb 2008 07:16:09 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-309906</guid>
		<description>&lt;a href=&quot;http://index5.logast.com&quot; rel=&quot;nofollow&quot;&gt;pan tractor seats&lt;/a&gt; &lt;a href=&quot;http://index20.logast.com&quot; rel=&quot;nofollow&quot;&gt;the radio station for 933 fm&lt;/a&gt; &lt;a href=&quot;http://index16.logast.com&quot; rel=&quot;nofollow&quot;&gt;olivia cruises &amp; resorts performers&lt;/a&gt; &lt;a href=&quot;http://index7.logast.com&quot; rel=&quot;nofollow&quot;&gt;fox news corporate phone numbers&lt;/a&gt; &lt;a href=&quot;http://index13.logast.com&quot; rel=&quot;nofollow&quot;&gt;baldwin police blotter&lt;/a&gt; &lt;a href=&quot;http://index14.logast.com&quot; rel=&quot;nofollow&quot;&gt;adventure city buena park&lt;/a&gt; &lt;a href=&quot;http://index4.logast.com&quot; rel=&quot;nofollow&quot;&gt;white orelander&lt;/a&gt; &lt;a href=&quot;http://index8.logast.com&quot; rel=&quot;nofollow&quot;&gt;minimum gpa for transfer to suny cortland&lt;/a&gt; &lt;a href=&quot;http://index19.logast.com&quot; rel=&quot;nofollow&quot;&gt;horizon foods&lt;/a&gt; &lt;a href=&quot;http://index18.logast.com&quot; rel=&quot;nofollow&quot;&gt;win back the one you love&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p><a href="http://index5.logast.com" rel="nofollow">pan tractor seats</a> <a href="http://index20.logast.com" rel="nofollow">the radio station for 933 fm</a> <a href="http://index16.logast.com" rel="nofollow">olivia cruises &amp; resorts performers</a> <a href="http://index7.logast.com" rel="nofollow">fox news corporate phone numbers</a> <a href="http://index13.logast.com" rel="nofollow">baldwin police blotter</a> <a href="http://index14.logast.com" rel="nofollow">adventure city buena park</a> <a href="http://index4.logast.com" rel="nofollow">white orelander</a> <a href="http://index8.logast.com" rel="nofollow">minimum gpa for transfer to suny cortland</a> <a href="http://index19.logast.com" rel="nofollow">horizon foods</a> <a href="http://index18.logast.com" rel="nofollow">win back the one you love</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rushui</title>
		<link>http://www.yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/comment-page-1/#comment-176925</link>
		<dc:creator>Rushui</dc:creator>
		<pubDate>Thu, 23 Aug 2007 15:31:48 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-176925</guid>
		<description>Ted

While you have a valid point, I disagree that current behavior of XMLHttpRequest is a problem or faulty design.  A true async operation should return when the operation is finished.  It shouldn&#039;t have dependency on when the operation is invoked.

Previous comments has shown that it is easy to cope with the async behavior to achieve your goal.  But if XMLHttpRequest is designed to have response return in invocation order, it will be very difficult to achieve true async operation, therefore make it useless on many other use cases.</description>
		<content:encoded><![CDATA[<p>Ted</p>
<p>While you have a valid point, I disagree that current behavior of XMLHttpRequest is a problem or faulty design.  A true async operation should return when the operation is finished.  It shouldn&#8217;t have dependency on when the operation is invoked.</p>
<p>Previous comments has shown that it is easy to cope with the async behavior to achieve your goal.  But if XMLHttpRequest is designed to have response return in invocation order, it will be very difficult to achieve true async operation, therefore make it useless on many other use cases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Billy</title>
		<link>http://www.yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/comment-page-1/#comment-132080</link>
		<dc:creator>Billy</dc:creator>
		<pubDate>Tue, 29 May 2007 18:53:00 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-132080</guid>
		<description>A valid use for a synchronous call: requests made onunload.

For example, you have a database application with a list view and a record view.  Records are locked when loaded and unlocked when unloaded.  The locking can be done server-side, but the unlocking needs to be done via a JavaScript request.

By the time the request is complete the page is gone.  If there was a callback function, it&#039;s gone.  If the loading of the next page is affected by the lock status, there is no guarantee that the XMLHttpRequest is finished before it starts loading.  You can&#039;t just put the unlock function on the list page, or in the link, because you don&#039;t know what the user is clicking on or if they might want to have two records open.</description>
		<content:encoded><![CDATA[<p>A valid use for a synchronous call: requests made onunload.</p>
<p>For example, you have a database application with a list view and a record view.  Records are locked when loaded and unlocked when unloaded.  The locking can be done server-side, but the unlocking needs to be done via a JavaScript request.</p>
<p>By the time the request is complete the page is gone.  If there was a callback function, it&#8217;s gone.  If the loading of the next page is affected by the lock status, there is no guarantee that the XMLHttpRequest is finished before it starts loading.  You can&#8217;t just put the unlock function on the list page, or in the link, because you don&#8217;t know what the user is clicking on or if they might want to have two records open.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Synchronous v. Asynchronous &#124; codelinkers</title>
		<link>http://www.yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/comment-page-1/#comment-124443</link>
		<dc:creator>Synchronous v. Asynchronous &#124; codelinkers</dc:creator>
		<pubDate>Wed, 23 May 2007 12:27:58 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-124443</guid>
		<description>[...] @ http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/    var addthis_pub = &#039;codelinkers&#039;;      Back to Codelinkers your virtual Link Sharing [...]</description>
		<content:encoded><![CDATA[<p>[...] @ <a href="http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/" rel="nofollow">http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/</a>    var addthis_pub = &#8216;codelinkers&#8217;;      Back to Codelinkers your virtual Link Sharing [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jake</title>
		<link>http://www.yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/comment-page-1/#comment-110864</link>
		<dc:creator>Jake</dc:creator>
		<pubDate>Fri, 11 May 2007 21:28:09 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-110864</guid>
		<description>Dealing with multiple request (like the colorado example give) is really not terribly difficult.

My solution was to track the XMLHttpRequest object in a variable (we&#039;ll call it xhr).

When an attempt to make a new Ajax call is made I check xhr to see if it is null.  If it is not I call xhr.abort() to kill the request (now it will not return, out of order or otherwise).  Then I set xhr = null and make the new request storing the new XMLHttpRequest object in xhr.

&lt;code&gt;var xhr = null;
function MakeAjaxCall() {
    if (xhr !== null) {
        xhr.abort();
        xhr = null;
    }
    
    xhr = new XMLHttpRequest(/* proper settings */);
    /* more code to complete the XMLHttpRequest */
}&lt;/code&gt;

I also add a delay when making Ajax requests from a UI component.  This gives the user a tiny moment to cycle through selects without my code making and aborting a lot of Ajax calls.

&lt;code&gt;var select_change_timeout = null;
var reasonable_delay = 100;  // or something reasonable
var select_element = document.getElementById(&quot;my_select_element&quot;);
select_element.onchange = function () {
	if (select_change_timeout !== null) {
		clearTimeout(select_change_timeout);
		select_change_timeout = null;
	}
	
	select_change_timeout = setTimeout(MakeAjaxCall, reasonable_delay);
};&lt;/code&gt;

&lt;i&gt;Disclaimer: code samples are simplified and untested and may not work for you.&lt;/i&gt;</description>
		<content:encoded><![CDATA[<p>Dealing with multiple request (like the colorado example give) is really not terribly difficult.</p>
<p>My solution was to track the XMLHttpRequest object in a variable (we&#8217;ll call it xhr).</p>
<p>When an attempt to make a new Ajax call is made I check xhr to see if it is null.  If it is not I call xhr.abort() to kill the request (now it will not return, out of order or otherwise).  Then I set xhr = null and make the new request storing the new XMLHttpRequest object in xhr.</p>
<p><code>var xhr = null;<br />
function MakeAjaxCall() {<br />
    if (xhr !== null) {<br />
        xhr.abort();<br />
        xhr = null;<br />
    }</p>
<p>    xhr = new XMLHttpRequest(/* proper settings */);<br />
    /* more code to complete the XMLHttpRequest */<br />
}</code></p>
<p>I also add a delay when making Ajax requests from a UI component.  This gives the user a tiny moment to cycle through selects without my code making and aborting a lot of Ajax calls.</p>
<p><code>var select_change_timeout = null;<br />
var reasonable_delay = 100;  // or something reasonable<br />
var select_element = document.getElementById("my_select_element");<br />
select_element.onchange = function () {<br />
	if (select_change_timeout !== null) {<br />
		clearTimeout(select_change_timeout);<br />
		select_change_timeout = null;<br />
	}</p>
<p>	select_change_timeout = setTimeout(MakeAjaxCall, reasonable_delay);<br />
};</code></p>
<p><i>Disclaimer: code samples are simplified and untested and may not work for you.</i></p>
]]></content:encoded>
	</item>
</channel>
</rss>

