AJAX - The Complete Reference

(avery) #1

252 Part II: Developing an Ajax Library^


In sendRequest(), a modification is made to set the position of a request in the queue and
save that value in responseQueueID:

/* Add a queueID if necessary */
if (request.enforceOrder)
request.responseQueueID = AjaxTCR.comm.queue._responseQueue.maxID++;

Later on, when a request returns and _handleResponse() is invoked, a check is made to
see if it is necessary to wait for another request as indicated by the enforceOrder flag.

if (response.enforceOrder)
AjaxTCR.comm.queue._handleQueue(response);
else
AjaxTCR.comm._handleCallbacks(response);

If response order is enforced, the private _handleQueue() method is called which puts
the response into the queue at its predefined sequenced position (queueID), and then looks
through the queue to see which requests, including the recent, can be passed on to
_handleCallbacks().

_handleQueue: function(response){
/* add response into queue */
AjaxTCR.comm.queue._responseQueue.queue[response.queueID] = response;

/* loop thru queue handling any received requests up to current point */
while (AjaxTCR.comm.queue._responseQueue.queue
[AjaxTCR.comm.queue._responseQueue.currentIndex] != undefined)
{

FIGURE 6-12 Request queues don’t always help
Free download pdf