Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deferred Error Testing
require([
"dojo/Deferred"
], function(Deferred){
var useError = 0 ;
var getError = function(name, useThisError){
var msg = name + ' error';
return useError || useThisError
?
function(e){ console.error(msg); d.reject(e); }
:
null;
}
var doZap = function(){
console.log('zap');
}
var doBar = function(){
throw new Error('BAR ERROR');
console.log('bar');
}
var doFoo = function(){
console.log('foo');
}
var d = new Deferred();
d
.then(
doZap,
getError('zap'), 0)
.then(
doBar, // throws an error
function(e){ console.error('e bar'); d.reject(e); }) // does not get called
.then(
doFoo,
getError('foo'), 0)
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