Dojo Tutorial: Getting Started with Deferreds

By on March 22, 2011 11:10 am

As part of our ongoing series of Dojo Tutorials we’re releasing our latest tutorial: Getting Started with Deferreds.

What’s a Deferred?

A Dojo feature since version 0.3, Deferreds are a simple, yet powerful mechanism that make it easy to work with asynchronous actions, such as Ajax requests. In its simplest form, a Deferred waits until a later time to perform an action; essentialy, you’re deferring the action until a prior action is completed. This feature is used throughout Dojo’s Ajax APIs which all return Deferreds.

Check it out!

Deferreds may let you delay an action until later, but don’t delay going to read this great tutorial!

Want to see a specific Tutorial? Want to Learn More?

Is there something you’d like to learn how to do with Dojo? Always wanted to know how something in Dojo works? Leave us a message in the blog comments and we’ll see about getting a tutorial created for you. Or sign-up for an upcoming SitePen Dojo Workshop to get a fully immersive hands-on experience with Dojo.

Other posts in the series


  • Ron MacCracken

    Great article! We use Deferreds a lot in our application, which brings me to a few questions/issues with them in Dojo 1.6.0.

    Previously in 1.3.2, we were able to derive a class (using dojo.declare) from dojo.Deferred to add our own functionality (explained a bit below). That no longer seems to work because of the way the “class” is written. Is there a way to do this now, or could the code be rewritten in future releases to allow it?

    The extra functionality we add to dojo.Deferred is to track user actions, which could be as easy as switching tabs to an action that pops up a dialog, waits for input, publishes to the server, and then refreshes the UI. Actions can include multiple Deferreds being used in succession, not necessarily all at once as in DeferredList. We do this to track action metrics such as time spent on server, on client, size of data sent to/from server, time to load images, etc. To do this we override dojo.Deferred with our own class to communicate with a DeferredManager to keep track of the metrics and call a final callback when the count of Deferreds goes to zero.

    Knowing when an action begins and ends is also of use for showing progress messages and disabling other actions while the action is processing.

    Has this functionality been done before or been thought of for the future?