Chapter 15.1.10. More about Callbacks

Early in this chapter, you saw how easy it is to add a callback and an errback (a callback for errors) to your Deferreds. What we didn’t talk about is what happens when you have more than one callback. Callbacks and errbacks are appended to a list, each element of which is called in order when the result arrives or the pending event occurs. Each callback gets the result of the previous callback as its parameter. This allows you to do useful transformations of the data that comes in.

For an example of this in action, we need look no further than MochiKit itself. We talked about using doSimpleXMLHttpRequest to perform an Ajax request. That function returns a Deferred that is later called back with the

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.