<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Synchronous v. Asynchronous</title>
	<link>http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/</link>
	<description>News and Artilces about Designing and Developing with Yahoo! Libraries.</description>
	<pubDate>Mon, 12 May 2008 09:37:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: Glen</title>
		<link>http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-356333</link>
		<dc:creator>Glen</dc:creator>
		<pubDate>Tue, 22 Apr 2008 17:04:02 +0000</pubDate>
		<guid>http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-356333</guid>
		<description>Here'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't been a session time-out.  If the session is timed out, and I no longer know who'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'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't, since YUI doesn'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 - 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 - 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 - 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://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-309906</link>
		<dc:creator>feechka-no</dc:creator>
		<pubDate>Thu, 21 Feb 2008 07:16:09 +0000</pubDate>
		<guid>http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-309906</guid>
		<description>&lt;a href="http://index5.logast.com" rel="nofollow"&gt;pan tractor seats&lt;/a&gt; &lt;a href="http://index20.logast.com" rel="nofollow"&gt;the radio station for 933 fm&lt;/a&gt; &lt;a href="http://index16.logast.com" rel="nofollow"&gt;olivia cruises &#38; resorts performers&lt;/a&gt; &lt;a href="http://index7.logast.com" rel="nofollow"&gt;fox news corporate phone numbers&lt;/a&gt; &lt;a href="http://index13.logast.com" rel="nofollow"&gt;baldwin police blotter&lt;/a&gt; &lt;a href="http://index14.logast.com" rel="nofollow"&gt;adventure city buena park&lt;/a&gt; &lt;a href="http://index4.logast.com" rel="nofollow"&gt;white orelander&lt;/a&gt; &lt;a href="http://index8.logast.com" rel="nofollow"&gt;minimum gpa for transfer to suny cortland&lt;/a&gt; &lt;a href="http://index19.logast.com" rel="nofollow"&gt;horizon foods&lt;/a&gt; &lt;a href="http://index18.logast.com" rel="nofollow"&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://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-176925</link>
		<dc:creator>Rushui</dc:creator>
		<pubDate>Thu, 23 Aug 2007 15:31:48 +0000</pubDate>
		<guid>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'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://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-132080</link>
		<dc:creator>Billy</dc:creator>
		<pubDate>Tue, 29 May 2007 18:53:00 +0000</pubDate>
		<guid>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'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't just put the unlock function on the list page, or in the link, because you don'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://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-124443</link>
		<dc:creator>Synchronous v. Asynchronous &#124; codelinkers</dc:creator>
		<pubDate>Wed, 23 May 2007 12:27:58 +0000</pubDate>
		<guid>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 = 'codelinkers';      Back to Codelinkers your virtual Link Sharing [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] @ <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 [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jake</title>
		<link>http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-110864</link>
		<dc:creator>Jake</dc:creator>
		<pubDate>Fri, 11 May 2007 21:28:09 +0000</pubDate>
		<guid>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'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("my_select_element");
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>
	<item>
		<title>By: Alexey Epishkin</title>
		<link>http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-105218</link>
		<dc:creator>Alexey Epishkin</dc:creator>
		<pubDate>Sat, 05 May 2007 06:27:57 +0000</pubDate>
		<guid>http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-105218</guid>
		<description>Wow, Yahoo! Connection Manager looks like Prototype ;-)
Actually I like prototype. Also Scriptaculous uses it.</description>
		<content:encoded><![CDATA[<p>Wow, Yahoo! Connection Manager looks like Prototype ;-)<br />
Actually I like prototype. Also Scriptaculous uses it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ajax-tr.com &#187; Asenkron ve Senkron Meselesi</title>
		<link>http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-41407</link>
		<dc:creator>ajax-tr.com &#187; Asenkron ve Senkron Meselesi</dc:creator>
		<pubDate>Sat, 03 Feb 2007 15:33:28 +0000</pubDate>
		<guid>http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-41407</guid>
		<description>[...] Synchronous v. Asynchronous [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Synchronous v. Asynchronous [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JIRA: Teradata Relationship Manager</title>
		<link>http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-40692</link>
		<dc:creator>JIRA: Teradata Relationship Manager</dc:creator>
		<pubDate>Fri, 02 Feb 2007 14:27:47 +0000</pubDate>
		<guid>http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-40692</guid>
		<description>&lt;strong&gt;[TRM-1108] Remove Synchronous Ajax calls from Seg SelectionDatasources.js...&lt;/strong&gt;

Synchronous Ajax calls lock the browser. If for some reason the request did not return, the only way to unlock the browser is to kill it from Task Manager. Sync calls are not considered good programming form. And dont take it from me, here is a blog o....</description>
		<content:encoded><![CDATA[<p><strong>[TRM-1108] Remove Synchronous Ajax calls from Seg SelectionDatasources.js&#8230;</strong></p>
<p>Synchronous Ajax calls lock the browser. If for some reason the request did not return, the only way to unlock the browser is to kill it from Task Manager. Sync calls are not considered good programming form. And dont take it from me, here is a blog o&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Confluence: Development Services Group</title>
		<link>http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-2248</link>
		<dc:creator>Confluence: Development Services Group</dc:creator>
		<pubDate>Fri, 23 Jun 2006 13:01:23 +0000</pubDate>
		<guid>http://yuiblog.com/blog/2006/04/04/synchronous-v-asynchronous/#comment-2248</guid>
		<description>&lt;strong&gt;Javascript and Ajax Items for Discussion...&lt;/strong&gt;

Items n links   Libs...</description>
		<content:encoded><![CDATA[<p><strong>Javascript and Ajax Items for Discussion&#8230;</strong></p>
<p>Items n links   Libs&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.544 seconds -->
