AJAX - The Complete Reference

(avery) #1

PART II


Chapter 6: Networking Considerations 249


Now, the previous example is quite simple, but what happens if we have a queue with
different priorities? Just as in real life, there are those who want to cut in line and those who
are willing to wait. For example, the modified queue could support a variety of states like
“normal,” which goes to the end of the line; “faster,” which goes in front of normal requests
but behind already queued priority requests; and some super high priority, which gets sent
out next no matter what. We’ll call that final priority “next” for short. To support the new
queue priority idea the AjaxTCR.comm.queue.add() method is modified to take an
optional third-parameter priority, a string containing either normal, faster, or next. By
default, if the priority is not specified it will be assumed to a normal request.
If an item should be removed from the request queue, call the AjaxTCR.comm.queue
.remove() method and pass it the requestQueueID that was created from the add()
method. Finally, in order to eliminate the entire queue call the public method AjaxTCR
.comm.queue.clear()to empty the queue. An example that allows you to explore the

FIGURE 6-9 Request queue fi xes timeout problem
Free download pdf