Skip to content

Commit b268b4a

Browse files
committed
Promise bugs
Fixed several bugs with promises.
1 parent 842d4d3 commit b268b4a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Sequencr.dev.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,22 @@ function Sequencr() {
4848
}
4949

5050
this.promiseChain = function(callbacks){
51-
var promise = null;
51+
var p = null;
5252
for(var i = 0; i < callbacks.length; i++){
53-
promise = promise ? promise.then(callbacks[i]) : callbacks[i]();
53+
p = p ? p.then(callbacks[i]) : callbacks[i]();
5454
}
55-
return promise;
55+
return p;
5656
}
5757

5858
this.promiseFor = function(startInclusive, endExclusive, callback, onCompleted){
59-
var promise = null;
59+
if(startInclusive >= endExclusive) throw "startInclusive must be less than endExclusive.";
60+
if(endExclusive == Infinity) throw "Infinite loops are now allowed.";
61+
var p = null;
6062
var j = startInclusive;
6163
for(var i = startInclusive; i < endExclusive; i++){
62-
promise = promise ? promise.then(function(){return callback(j++)}) : callback(j++);
64+
p = p ? p.then(function(){return callback(j++)}) : callback(j++);
6365
}
64-
return promise;
66+
return p;
6567
}
6668
}
6769

Sequencr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ and to permit persons to whom the Software is furnished to do so, subject to the
1212
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1313
*/
1414

15-
function Sequencr(){this.chain=function(n,t){var r;Sequencr["for"].apply(this,[0,n.length,function(t){r=void 0===r?n[t].call(this):n[t].call(this,r)},t])},this["for"]=function(n,t,r,c,i){t>n?setTimeout(function(l){var o=r.call(l,n);o!==!1?Sequencr["for"].apply(l,[n+1,t,r,c,i]):i&&i.call(this,!1)},c&&c.constructor&&c.call&&c.apply?c(n)||1:c||1,this):i&&i.call(this,!0)},this["do"]=function(n,t){setTimeout(function(r){var c=n.call(r);c!==!1&&Sequencr["do"].apply(r,[n,t])},t&&t.constructor&&t.call&&t.apply?t()||1:t||1,this)},this.promiseChain=function(n){for(var t=null,r=0;r<n.length;r++)t=t?t.then(n[r]):n[r]();return t},this.promiseFor=function(n,t,r,c){for(var i=null,l=n,o=n;t>o;o++)i=i?i.then(function(){return r(l++)}):r(l++);return i}}var Sequencr=new Sequencr;
15+
function Sequencr(){this.chain=function(n,t){var i;Sequencr["for"].apply(this,[0,n.length,function(t){i=void 0===i?n[t].call(this):n[t].call(this,i)},t])},this["for"]=function(n,t,i,e,r){t>n?setTimeout(function(l){var o=i.call(l,n);o!==!1?Sequencr["for"].apply(l,[n+1,t,i,e,r]):r&&r.call(this,!1)},e&&e.constructor&&e.call&&e.apply?e(n)||1:e||1,this):r&&r.call(this,!0)},this["do"]=function(n,t){setTimeout(function(i){var e=n.call(i);e!==!1&&Sequencr["do"].apply(i,[n,t])},t&&t.constructor&&t.call&&t.apply?t()||1:t||1,this)},this.promiseChain=function(n){for(var t=null,i=0;i<n.length;i++)t=t?t.then(n[i]):n[i]();return t},this.promiseFor=function(n,t,i,e){if(n>=t)throw"startInclusive must be less than endExclusive.";if(t==1/0)throw"Infinite loops are now allowed.";for(var r=null,l=n,o=n;t>o;o++)r=r?r.then(function(){return i(l++)}):i(l++);return r}}var Sequencr=new Sequencr;

0 commit comments

Comments
 (0)