Comparing version 1.2.4 to 1.3.0
function easyFor(obj, func, concurrency, last){ | ||
var max = 0; | ||
var isArr = obj instanceof Array; | ||
var isNum = false; | ||
var keys = null; | ||
@@ -12,3 +13,8 @@ | ||
} | ||
else throw "first argument is not Array or Object => " + obj; | ||
else if(typeof obj === 'number' && obj >= 0) | ||
{ | ||
isNum = true; | ||
max = obj; | ||
} | ||
else throw "first argument is not Array or Object or number of iterations => " + obj; | ||
@@ -50,2 +56,3 @@ if((arguments.length === 3 || arguments.length === 4) && typeof func === 'number' && typeof concurrency === 'function') | ||
if(isArr) func(count.start, obj[count.start++], next); | ||
else if(isNum) func(count.start++, next); | ||
else func(keys[count.start], obj[keys[count.start++]], next); | ||
@@ -52,0 +59,0 @@ if(max > count.start && count.processing < concurrency) run(); |
@@ -6,2 +6,3 @@ /** | ||
var easyFor = require('./easy-for'); | ||
var easyManual = require('./easy-manual'); | ||
@@ -20,3 +21,4 @@ function loop(obj, func, concurrency, last){ | ||
loop["for"] = loop["while"] = loop["loop"] = loop["forEach"] = loop; | ||
loop["create"] = easyManual; | ||
module.exports = loop; |
{ | ||
"name": "easy-loop", | ||
"version": "1.2.4", | ||
"version": "1.3.0", | ||
"description": "Easy sync loop processing for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/easy-loop", |
@@ -259,2 +259,71 @@ | ||
Result : Now Second : 22 | ||
*/ | ||
console.log("Case9 Start => When only know the number of iterations. 2 arguments or 3 arguments(concurrency) and break possible"); | ||
console.log("Start : Now Second : ", new Date().getSeconds()); | ||
var loopCount = 5; | ||
loop(loopCount, function(i, next){ | ||
setTimeout(function(){ | ||
console.log(i, "Date : ", new Date().getSeconds()); | ||
next(); // break => next(err); | ||
}, 1000); | ||
}, function(err){ | ||
console.log("err : ", err); | ||
console.log("Case 9 result"); | ||
console.log("Result : Now Second : ", new Date().getSeconds()); | ||
}); | ||
console.log("Case9 End"); | ||
/* | ||
Case9 Start => When only know the number of iterations. 2 arguments or 3 arguments(concurrency) and break possible | ||
Start : Now Second : 23 | ||
Case9 End | ||
0 'Date : ' 24 | ||
1 'Date : ' 25 | ||
2 'Date : ' 26 | ||
3 'Date : ' 27 | ||
4 'Date : ' 28 | ||
err : undefined | ||
Case 9 result | ||
Result : Now Second : 28 | ||
*/ | ||
console.log("Case10 Start => When only know the number of iterations. break possible"); | ||
console.log("Start : Now Second : ", new Date().getSeconds()); | ||
var handle = loop.create(10, function(err){ | ||
console.log("err : ", err); | ||
console.log("Case 10 result"); | ||
console.log("Result : Now Second : ", new Date().getSeconds()); | ||
}); | ||
for(var i=0; i<10; i++) | ||
{ | ||
setTimeout(function(){ | ||
console.log("Date : ", new Date().getSeconds()); | ||
handle.next(); // break => handle.next(err); | ||
}, 1000); | ||
} | ||
console.log("Case10 End"); | ||
/* | ||
Case10 Start => When only know the number of iterations | ||
Start : Now Second : 20 | ||
Case10 End | ||
Date : 21 | ||
Date : 21 | ||
Date : 21 | ||
Date : 21 | ||
Date : 21 | ||
Date : 21 | ||
Date : 21 | ||
Date : 21 | ||
Date : 21 | ||
Date : 21 | ||
err : undefined | ||
Case 10 result | ||
Result : Now Second : 21 | ||
*/ |
@@ -83,3 +83,3 @@ //var fs = require('fs'); | ||
*/ | ||
var arr = []; | ||
@@ -102,3 +102,3 @@ for(var i=0; i<10000; i++) arr.push(i); | ||
/* | ||
var num = 0; | ||
@@ -139,3 +139,3 @@ console.log("Case7 Start => while and 3 arguments"); | ||
console.log("err : ", err); | ||
console.log("Case 7 result"); | ||
console.log("Case 8 result"); | ||
console.log("Result : Now Second : ", new Date().getSeconds()); | ||
@@ -145,1 +145,36 @@ }); | ||
*/ | ||
/* | ||
console.log("Case9 Start => When only know the number of iterations. 2 or 3 arguments possible"); | ||
console.log("Start : Now Second : ", new Date().getSeconds()); | ||
var loopCount = 5; | ||
loop(loopCount, function(i, next){ | ||
setTimeout(function(){ | ||
console.log(i, "Date : ", new Date().getSeconds()); | ||
next(); | ||
}, 1000); | ||
}, function(err){ | ||
console.log("err : ", err); | ||
console.log("Case 9 result"); | ||
console.log("Result : Now Second : ", new Date().getSeconds()); | ||
}); | ||
console.log("Case9 End"); | ||
*/ | ||
/* | ||
console.log("Case10 Start => When only know the number of iterations"); | ||
console.log("Start : Now Second : ", new Date().getSeconds()); | ||
var handle = loop.create(10, function(err){ | ||
console.log("err : ", err); | ||
console.log("Case 10 result"); | ||
console.log("Result : Now Second : ", new Date().getSeconds()); | ||
}); | ||
for(var i=0; i<10; i++) | ||
{ | ||
setTimeout(function(){ | ||
console.log("Date : ", new Date().getSeconds()); | ||
handle.next(); | ||
}, 1000); | ||
} | ||
console.log("Case10 End"); | ||
*/ |
17245
9
300
328