Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement done() - terminates a Promise chain, rethrowing unhandled rejections as Errors #4

Open
johnyanarella opened this issue Nov 15, 2013 · 0 comments
Assignees

Comments

@johnyanarella
Copy link
Member

Implement done() and add to README.md.

One of the pitfalls of interacting with Promise-based APIs is the tendency for important errors to be silently swallowed unless an explicit rejection handler is specified.

For example:

promise
  .then( function () {
    // logic in your callback throws an error
    // and it is interpreted as a rejection.
    throw new Error('Boom!');
  });

// The error is silently swallowed.

This problem can be addressed by terminating the Promise chain with the done() method:

promise
  .then( function () {
    // logic in your callback throws an error
    // and it is interpreted as a rejection.
    throw new Error('Boom!');
  })
  .done();

// The error is thrown on the next tick of the event loop.

The done() method ensures that any unhandled rejections are rethrown as Errors.

@ghost ghost assigned johnyanarella Nov 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant