Skip to content

Instantly share code, notes, and snippets.

@kriskowal
Forked from nrstott/gist:1444106
Created December 7, 2011 18:59
Show Gist options
  • Select an option

  • Save kriskowal/1444114 to your computer and use it in GitHub Desktop.

Select an option

Save kriskowal/1444114 to your computer and use it in GitHub Desktop.
var q = require('q');
var a = q.defer();
var b = q.defer();
q.when(a, function() {
console.log('calling b');
return q.when(b, function() {
console.log('throwing');
throw new Error('Hello World');
}, function (error) {
console.log('handling error for b, rethrowing');
throw error;
});
}, function() {
console.log('handling error for a');
})
.fail(function () {
console.log('handling error for anything above');
});
b.resolve('hi');
a.resolve('yo');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment