Skip to content

Instantly share code, notes, and snippets.

@stith
Last active August 29, 2015 13:57
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 stith/9905347 to your computer and use it in GitHub Desktop.
Save stith/9905347 to your computer and use it in GitHub Desktop.
doStuff().then(function(things) {
if (!things) {
throw new Error("Here I want to skip everything else, including the 'then's after the next catch..");
}
if (canMakeNewThing) {
// This should continue to the next 'then'
return someNewThing.save();
}
return doSomeOtherThingsFirst().then(function(hold) {
return doMoreOtherThings(); // Should continue to the next 'then'
}).catch(function(err) {
throw new Error("This should skip the remaining thens as well..");
});
}, function(err) {
throw new Error(); // Skip the next then.
}).then(function() {
req.flash('success', 'Reserved!');
res.redirect('/blah');
}, function(err) {
console.log("Bailed.", err.stack);
// Don't do any rendering here, this is where errors go.
});
var things = yield doStuff();
if (!things) {
throw new Error("easy");
}
if (canMakeNewThing) {
var newThing = yield someNewThing.save();
}
yield doSomeOtherThingsFirst();
yield doMoreOtherThings();
req.flash('success', 'Woot!');
res.redirect('/blah');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment