Skip to content

Instantly share code, notes, and snippets.

@novemberborn
Forked from mikewilcox/Deferred.js
Created June 7, 2012 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save novemberborn/2890709 to your computer and use it in GitHub Desktop.
Save novemberborn/2890709 to your computer and use it in GitHub Desktop.
Deferred Error Testing
require([
"dojo/Deferred"
], function(Deferred){
var useError = 0;
var getError = function(name, useThisError){
var msg = name + ' error';
if(useError || useThisError){
return function(e){ console.error(msg); d.reject(e); };
}
};
var doZap = function(){
console.log('zap');
};
var doBar = function(){
console.log('bar');
throw new Error('BAR ERROR');
};
var doFoo = function(){
console.log('foo');
};
var d = new Deferred();
d.then(
doZap,
getError('zap')
).then(
doBar, // throws an error
function(e){ console.error('e bar'); d.reject(e); } // does not get called
).then(
doFoo,
getError('foo')
);
d.resolve();
console.log('rejected:', d.isRejected(), 'fullfilled:', d.isFulfilled()); // not correct
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment