Skip to content

Commit

Permalink
Added ability to break from Sequencr.for
Browse files Browse the repository at this point in the history
Break by returning false in the main callback.
  • Loading branch information
JSideris committed Jun 10, 2016
1 parent 7961416 commit af1d76f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sequencr.js
# Sequencr.js V2
Sequencr.js is a super-light-weight library that allows you to easily chain function calls together with timeouts in between, or set timeouts between iterations of a loop.

Please read the wiki for more information, and usage.
Expand Down
11 changes: 9 additions & 2 deletions Sequencr.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*
Sequencr.js V2
The MIT License (MIT)
Copyright (c) 2016 Joshua Sideris | [email protected] | https://github.com/JSideris/Sequencr.js
Expand All @@ -20,8 +22,13 @@ function Sequencr() {
this.for = function (startInclusive, endExclusive, callback, timeout, onCompleted) {
if (startInclusive < endExclusive) {
setTimeout(function (This) {
callback.call(This, startInclusive);
Sequencr.for.apply(This, [startInclusive + 1, endExclusive, callback, timeout, onCompleted]);
var ret = callback.call(This, startInclusive);
if(ret !== false){
Sequencr.for.apply(This, [startInclusive + 1, endExclusive, callback, timeout, onCompleted]);
}
else if(onCompleted) {
onCompleted.call(this);
}
}, timeout, this);
}
else if(onCompleted) {
Expand Down
4 changes: 3 additions & 1 deletion Sequencr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*
Sequencr.js V2
The MIT License (MIT)
Copyright (c) 2016 Joshua Sideris | [email protected] | https://github.com/JSideris/Sequencr.js
Expand All @@ -10,4 +12,4 @@ and to permit persons to whom the Software is furnished to do so, subject to the
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/

function Sequencr(){this.chain=function(n,c){Sequencr["for"].apply(this,[0,n.length,function(c){n[c].call(this)},c])},this["for"]=function(n,c,e,t,i){c>n?setTimeout(function(u){e.call(u,n),Sequencr["for"].apply(u,[n+1,c,e,t,i])},t,this):i&&i.call(this)}}var Sequencr=new Sequencr;
function Sequencr(){this.chain=function(n,c){Sequencr["for"].apply(this,[0,n.length,function(c){n[c].call(this)},c])},this["for"]=function(n,c,t,e,i){c>n?setTimeout(function(l){var u=t.call(l,n);u!==!1?Sequencr["for"].apply(l,[n+1,c,t,e,i]):i&&i.call(this)},e,this):i&&i.call(this)}}var Sequencr=new Sequencr;
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Changes
V2 - 2016-06-09
Added ability to break out of a for loop by returning false. This will immediately invoke the onCompleted callback.

0 comments on commit af1d76f

Please sign in to comment.