added a test and fixed some bugs. yay!

This commit is contained in:
AJ ONeal 2013-08-06 02:51:22 -07:00
parent 4890f3ac92
commit 1a4ba1c41e
2 changed files with 19 additions and 3 deletions

View File

@ -8,15 +8,16 @@
;
function next(BREAK, newArr) {
if (0 === arr.length || BREAK === forEachAsync.__BREAK) {
index += 1;
if (index === arr.length || BREAK === forEachAsync.__BREAK) {
dones.forEach(function (done) {
done.call(thisArg, newArr);
});
return;
}
index += 1;
fn.call(thisArg, next, arr.shift(), index, arr);
fn.call(thisArg, next, arr[index], index, arr);
}
setTimeout(next, 4);

15
test.js Normal file
View File

@ -0,0 +1,15 @@
(function () {
"use strict";
var forEachAsync = require('../forEachAsync').forEachAsync
;
forEachAsync([0, 500, 70, 800], function (next, element, i, arr) {
console.log(element, 'is element', i, 'of', arr.length);
this[element] = i;
setTimeout(next, element);
}, {}).then(function () {
console.log(this);
});
}());