Skip to content

Instantly share code, notes, and snippets.

@aaronj1335
Created October 23, 2012 02:39
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 aaronj1335/3936362 to your computer and use it in GitHub Desktop.
Save aaronj1335/3936362 to your computer and use it in GitHub Desktop.
optionally returning a deferred
something.then(function() {
if (config.somethingElse) {
return somethingElse();
}
});
@aaronj1335
Copy link
Author

so assuming that something and somethingElse return promises, the return value of the callback passed to .then() will return either a promise, or undefined.

is this ok? i'm paranoid that an error is going to get thrown and won't get caught.

@aaronj1335
Copy link
Author

also: i'm using q, and if i want to ensure that any exceptions thrown are caught, i would need to add a .end() after the .then() correct?

@medikoo
Copy link

medikoo commented Oct 23, 2012

It's perfectly ok. The final result would be undefined or resolved value of promise returned by somethingElse. Test it :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment