This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fixing the promise infinity loop

Now the promise chain does not add new promises from now until the end
of time
  • Loading branch information...
pspeter3 committed Aug 25, 2013
1 parent cab0982 commit 4896bd367132dbaf077e603dd99e3f55fe11aaa6
Showing with 7 additions and 1 deletion.
  1. +7 −1 lib/promise.js
@@ -33,7 +33,9 @@ var resolve = function(promise) {
callback[promise.state](promise.value);
}

next(resolver);
if (promise.callbacks.length > 0) {
next(resolver);
}
};

next(resolver);
@@ -118,6 +120,10 @@ Promise.prototype.then = function(onFulfilled, onRejected) {
callbacks[State.REJECTED] = handle(promise, State.REJECTED, onRejected);
this.callbacks.push(callbacks);

if (this.state !== State.PENDING) {
resolve(this);
}

return promise;
};

0 comments on commit 4896bd3

Please sign in to comment.