Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Return same promise if no handler is provided. #110

Merged
merged 1 commit into from

2 participants

@Twisol

This is the return self optimization, split off from #102.

@briancavalier briancavalier merged commit 70f0b15 into from
@Twisol Twisol deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 20, 2013
  1. @Twisol
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 6 deletions.
  1. +10 −6 when.js
View
16 when.js
@@ -352,14 +352,16 @@ define(function () {
* @return {Promise} fulfilled promise
*/
function fulfilled(value) {
- return new Promise(function (onFulfilled) {
+ var self = new Promise(function (onFulfilled) {
try {
- return coerce(typeof onFulfilled == 'function'
- ? onFulfilled(value) : value);
+ return typeof onFulfilled == 'function'
+ ? coerce(onFulfilled(value)) : self;
} catch (e) {
return rejected(e);
}
});
+
+ return self;
}
/**
@@ -371,14 +373,16 @@ define(function () {
* @return {Promise} rejected promise
*/
function rejected(reason) {
- return new Promise(function (_, onRejected) {
+ var self = new Promise(function (_, onRejected) {
try {
- return coerce(typeof onRejected == 'function'
- ? onRejected(reason) : rejected(reason));
+ return typeof onRejected == 'function'
+ ? coerce(onRejected(reason)) : self;
} catch (e) {
return rejected(e);
}
});
+
+ return self;
}
/**
Something went wrong with that request. Please try again.