Section 3.35. Welcome to the world of asynchrony


3.35. Welcome to the world of asynchrony!

It's been a long ride, but you should have everything in place to get your co-workers all the caffeine they want, without any waiting. Be sure you've made the changes to ajax.js and coffee.js so that there are two request objects used: one for each coffee maker.

Place coffee orders for Jim and Bob, and get both coffee makers brewing.

Jim's order comes back ready from the first coffee maker...

...and Bob's order comes back from the second coffee maker!

That's all fine, but I want to see what happens in this application when it's not asynchronous. I want to compare the synchronous and asynchronous versions, and see if the asynchronous version is really that much better.

3.35.1. Skeptical?

So, you want to see for yourself how different the Coffee Maker program is as a synchronous application? That's easy to do. All you have to do is change the third argument of the call to request.open() in the sendRequest() function: switch it from true to false:

     function sendRequest(request, url) {       request.onreadystatechange = serveDrink;       request.open("GET", url, false);Change the argument       from true to false to tell your application to send the request to the       coffee makers on the server synchronously.       Then give it a try. What happens?       request.send(null);     } 




Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net