Chapter 15.1.8. Canceling Deferreds

What if that large pepperoni pizza ordered in the preceding section has arrived? Do you still want the 30-minute timer alert box to pop up? Probably not.

Deferreds have a cancel method that allows you to cancel the Deferred before it has received a value. Both wait and callLater return a cancelable Deferred. If you hang on to the Deferred in a variable that’s available to scripts on the whole page, you can create a “My Pizza Has Arrived” button that calls d.cancel() when the button is pushed.

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.