Skip to content

Commit

Permalink
Make settle unreport already-rejected promises. Fix #423
Browse files Browse the repository at this point in the history
  • Loading branch information
briancavalier committed Jan 28, 2015
1 parent d892650 commit 31f50e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/decorators/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,12 @@ define(function(require) {

function settleOne(p) {
var h = Promise._handler(p);
return h.state() === 0 ? toPromise(p).then(state.fulfilled, state.rejected)
: state.inspect(h);
if(h.state() === 0) {
return toPromise(p).then(state.fulfilled, state.rejected);
}

h._unreport();
return state.inspect(h);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions test/settle-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var buster = typeof window !== 'undefined' ? window.buster : require('buster');
var assert = buster.assert;
var refute = buster.refute;
var fail = buster.referee.fail;

var when = require('../when');
Expand Down Expand Up @@ -66,5 +67,16 @@ buster.testCase('when.settle', {
assertFulfilled(settled[1], sentinel);
assertRejected(settled[2], sentinel);
});
},

'should not report unhandled rejection for rejected inputs': function(done) {
var P = when.Promise;
var spy = P.onPotentiallyUnhandledRejection = this.spy();
when.settle([when.reject()]);

setTimeout(function() {
refute.called(spy);
done();
}, 10);
}
});

0 comments on commit 31f50e8

Please sign in to comment.