you’re on your way 4
145
asynchronous applications
Building an Ajax-powered coffee maker
Two coffee makers...
...and a whole ofce of caffeine addicts.
As the ofcial “coffee pot manager,” it’s your job to make sure that the caffeine
needs of your ofcemates are met... and quickly, at that. All your mates are
caffeine addicts, and they get a bit testy if there’s no fresh coffee on hand. Good
thing that there are two coffee makers; even if one order is being brewed, your
co-workers can place another order, and have it lled by the second coffee maker.
You’re going to build an Ajax application to allow
your co-workers to order their coffee online.
You don’t want anyone coming after you with empty coffee cups, so let’s write an
Ajax application for ordering coffee and keeping track of the status of both coffee
makers. Here’s what it will look like:
Here’s the second coffee
maker. If an order is brewing
in coffee maker #1, this
coffee maker will handle any
additional orders. Just like
coffee maker #1, it takes a
little time to brew a cup.
This is the main
coffee maker. Anytime
an order is placed, and
no coffee is brewing,
this coffee maker
handles the order. It
takes a little time to
brew a cup, though,
and the coffee maker
can only brew one cup
at a time.
Here’s where you place
your order. You enter
your name, the size of
the cup you want, and
what type of beverage
you’re interested in. ...