Skip to content

Commit

Permalink
Minor perf tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
briancavalier committed Mar 12, 2014
1 parent fac32f3 commit 86131fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 2 additions & 5 deletions lib/makePromise.js
Expand Up @@ -241,7 +241,7 @@ define(function() {
InternalPromise.prototype = Object.create(Promise.prototype);

/**
* Create an appropriate handler for x
* Get an appropriate handler for x
* @param {*} x
* @param {object?} h optional handler to check for cycles
* @returns {object} handler
Expand Down Expand Up @@ -368,14 +368,11 @@ define(function() {

this.resolved = true;
this.handler = handler;
tasks.enqueue(this);

if(this._isMonitored()) {
this.trace = handler._addTrace(this.trace);
}

if(this.consumers.length > 0) {
tasks.enqueue(this);
}
};

DeferredHandler.prototype.when = function(resolve, notify, t, receiver, f, r, u) {
Expand Down
3 changes: 2 additions & 1 deletion when.js
Expand Up @@ -74,7 +74,8 @@ define(function (require) {
* callback and/or errback is not supplied.
*/
function when(x, onFulfilled, onRejected, onProgress) {
return resolve(x).then(onFulfilled, onRejected, onProgress);
var p = resolve(x);
return arguments.length < 2 ? p : p.then(onFulfilled, onRejected, onProgress);
}

/**
Expand Down

0 comments on commit 86131fc

Please sign in to comment.