Skip to content

Commit af1d76f

Browse files
committed
Added ability to break from Sequencr.for
Break by returning false in the main callback.
1 parent 7961416 commit af1d76f

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Sequencr.js
1+
# Sequencr.js V2
22
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.
33

44
Please read the wiki for more information, and usage.

Sequencr.dev.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
Sequencr.js V2
3+
24
The MIT License (MIT)
35
Copyright (c) 2016 Joshua Sideris | [email protected] | https://github.com/JSideris/Sequencr.js
46
@@ -20,8 +22,13 @@ function Sequencr() {
2022
this.for = function (startInclusive, endExclusive, callback, timeout, onCompleted) {
2123
if (startInclusive < endExclusive) {
2224
setTimeout(function (This) {
23-
callback.call(This, startInclusive);
24-
Sequencr.for.apply(This, [startInclusive + 1, endExclusive, callback, timeout, onCompleted]);
25+
var ret = callback.call(This, startInclusive);
26+
if(ret !== false){
27+
Sequencr.for.apply(This, [startInclusive + 1, endExclusive, callback, timeout, onCompleted]);
28+
}
29+
else if(onCompleted) {
30+
onCompleted.call(this);
31+
}
2532
}, timeout, this);
2633
}
2734
else if(onCompleted) {

Sequencr.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
Sequencr.js V2
3+
24
The MIT License (MIT)
35
Copyright (c) 2016 Joshua Sideris | [email protected] | https://github.com/JSideris/Sequencr.js
46
@@ -10,4 +12,4 @@ and to permit persons to whom the Software is furnished to do so, subject to the
1012
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1113
*/
1214

13-
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;
15+
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;

changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#Changes
2+
V2 - 2016-06-09
3+
Added ability to break out of a for loop by returning false. This will immediately invoke the onCompleted callback.

0 commit comments

Comments
 (0)