Skip to content
briancavalier edited this page Jan 9, 2012 · 5 revisions

when.js + Dojo Deferred

when.js works great with Dojo's Deferred. All of the extra goodies, like when.all(), when.map(), when.reduce(), etc. accept Dojo Deferred. They'll even work with a mixed array of Dojo Deferred (or deferred.promise), when.js Promise or Deferred, any other Promises/A promise, and immediate values. This is one of the advantages of when() (read more here).

Similarly, dojo.when() (aka Deferred.when() in Dojo 1.7) can accept a when.js Promise. When you pass a when.js Promise to dojo.when(), it will return a when.js Promise.

Dojo 1.7 Builder

Here is a Dojo 1.7 Builder profile that you can use to include when.js in a build with Dojo. Thanks to bryanforbes for contributing this profile!

// Save this as when.profile.js in the when.js dir
var profile = (function(){
	var testRE = /^when\/test\//;
	return {
		resourceTags: {
            test: function(filename, mid){
				// Tag test files as such
                return testRE.test(mid);
            },
            amd: function(filename, mid){
				// Tag the module as AMD so it doesn't get
				// wrapped by the Dojo builder
                return mid == "when/when" || mid == "when";
            },
            copyOnly: function(filename, mid){
				// Don't process package.json
                return mid == "when/package.json";
            }
		}
	};
})();
Clone this wiki locally