Browse Source

v1.0.3: use index as well

master v1.0.3
AJ ONeal 4 years ago
parent
commit
178672ad0d
  1. 2
      batchasync.js
  2. 5
      package-lock.json
  3. 2
      package.json
  4. 11
      test.js

2
batchasync.js

@ -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

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

2
package.json

@ -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

@ -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) {

Loading…
Cancel
Save