Skip to content

Instantly share code, notes, and snippets.

@mikewilcox
Created June 7, 2012 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikewilcox/2889873 to your computer and use it in GitHub Desktop.
Save mikewilcox/2889873 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';
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