196
Chapter 3
That’s all ne, 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.
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);
request.send(null);
}
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?
synchrony versus asynchrony