Skip to content

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

@johnyanarella

Description

@johnyanarella

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions