Skip to content

Commit

Permalink
Handle returning any promise implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
i20 committed Apr 4, 2020
1 parent 4b54449 commit f040422
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Promise.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ function Promise (_executor) {

const result = (_state === STATE_RESOLVED ? resolve || noopResolve : reject || noopReject)(_value);

// If handler returns a promise then, it "replaces" the current promise
if (result instanceof Promise)
// If handler returns a promise then current promise resolution is bound to returned's one
// Assimilate all thenable objects to handled returning a variety of other promise implementations
// Natives, Qs, Bluebirds, ZoneAwarePromises ...
if (result && typeof result.then === 'function')
result.then(nextResolve, nextReject, nextNotify);

else nextResolve(result);
Expand Down
6 changes: 4 additions & 2 deletions Promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ function Promise (_executor) {

var result = (_state === STATE_RESOLVED ? resolve || noopResolve : reject || noopReject)(_value);

// If handler returns a promise then, it "replaces" the current promise
if (result instanceof Promise)
// If handler returns a promise then current promise resolution is bound to returned's one
// Assimilate all thenable objects to handled returning a variety of other promise implementations
// Natives, Qs, Bluebirds, ZoneAwarePromises ...
if (result && typeof result.then === 'function')
result.then(nextResolve, nextReject, nextNotify);

else nextResolve(result);
Expand Down

0 comments on commit f040422

Please sign in to comment.