Skip to content

Commit

Permalink
Fix duplicate promise rejections.
Browse files Browse the repository at this point in the history
We can just reuse chained dispatched rejected promises.

The test was also broken; it needs to check for emptiness after fail()
runs.

Fixes kriskowal#238.
  • Loading branch information
SLaks authored and domenic committed May 10, 2013
1 parent 430a352 commit bba609d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- `isPromise` and `isPromiseAlike` now always returns a boolean
(even for falsy values). #284 @lfac-pt
- Support for ES6 Generators in `async` #288 @andywingo
- Clear duplicate promise rejections from dispatch methods #238 @SLaks

## 0.9.3

Expand Down
2 changes: 1 addition & 1 deletion q.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ function reject(reason) {
return rejected ? rejected(reason) : this;
}
}, function fallback() {
return reject(reason);
return this;
}, function valueOf() {
return this;
}, reason, true);
Expand Down
6 changes: 3 additions & 3 deletions spec/q-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2423,10 +2423,10 @@ describe("unhandled rejection reporting", function () {
});

it("doesn't report when you chain off a rejection", function () {
Q.reject("this will be handled").get("property").fail(function () {
return Q.reject("this will be handled").get("property").fail(function () {
// now it should be handled.
}).fin(function() {
expect(Q.unhandledReasons.length).toEqual(0);
});

expect(Q.unhandledReasons.length).toEqual(0);
});
});

0 comments on commit bba609d

Please sign in to comment.