v1.0.3: use index as well

This commit is contained in:
AJ ONeal 2019-11-25 16:05:46 -07:00
parent 9beae76631
commit 178672ad0d
4 changed files with 13 additions and 7 deletions

View File

@ -37,7 +37,7 @@
var p;
try {
p = doStuff(task);
p = doStuff(task, index, arr);
} catch (e) {
// we need to handle, and bubble, synchronous errors
error = e;

5
package-lock.json generated Normal file
View File

@ -0,0 +1,5 @@
{
"name": "batchasync",
"version": "1.0.3",
"lockfileVersion": 1
}

View File

@ -1,6 +1,6 @@
{
"name": "batchasync",
"version": "1.0.2",
"version": "1.0.3",
"description": "Like forEachAsync, or Promise.all(), but handling a bounded number of items at any given time.",
"main": "batchasync.js",
"scripts": {

11
test.js
View File

@ -6,11 +6,12 @@
function testBatch() {
var timeouts = [100, 80, 20, 500, 50, 30, 200, 300];
console.info(timeouts);
var tasks = timeouts.map(function(timeout, i) {
return function() {
return promiseTimeout(timeout).then(function() {
console.log("task:", i, timeouts[i]);
return i;
//console.log("task:", i, timeouts[i]);
return i + ":" + timeouts[i];
});
};
});
@ -71,7 +72,7 @@
}
return null;
})
.then(function(results) {
.then(function(/*results*/) {
var e = new Error("should not pass sync exception!");
e.FAIL = true;
throw e;
@ -90,7 +91,7 @@
}
function promiseTimeout(timeout) {
return new Promise(function(resolve, reject) {
return new Promise(function(resolve) {
setTimeout(resolve, timeout);
});
}
@ -99,7 +100,7 @@
.then(function() {
console.info("PROBABLY PASSED");
console.info(
"We tested what could be tested without knowing Passed what could be tested Do the results make sense?"
"We tested what could be tested. Do the results make sense?"
);
})
.catch(function(e) {