added a test and fixed some bugs. yay!
This commit is contained in:
parent
4890f3ac92
commit
1a4ba1c41e
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
}());
|
Loading…
Reference in New Issue