summaryrefslogtreecommitdiff
path: root/node_modules/foreachasync/forEachAsync.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/foreachasync/forEachAsync.js')
-rw-r--r--node_modules/foreachasync/forEachAsync.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/node_modules/foreachasync/forEachAsync.js b/node_modules/foreachasync/forEachAsync.js
new file mode 100644
index 0000000..8790d78
--- /dev/null
+++ b/node_modules/foreachasync/forEachAsync.js
@@ -0,0 +1,35 @@
+/*jshint -W054 */
+;(function (exports) {
+ 'use strict';
+
+ function forEachAsync(arr, fn, thisArg) {
+ var dones = []
+ , index = -1
+ ;
+
+ function next(BREAK, result) {
+ index += 1;
+
+ if (index === arr.length || BREAK === forEachAsync.__BREAK) {
+ dones.forEach(function (done) {
+ done.call(thisArg, result);
+ });
+ return;
+ }
+
+ fn.call(thisArg, next, arr[index], index, arr);
+ }
+
+ setTimeout(next, 4);
+
+ return {
+ then: function (_done) {
+ dones.push(_done);
+ return this;
+ }
+ };
+ }
+ forEachAsync.__BREAK = {};
+
+ exports.forEachAsync = forEachAsync;
+}('undefined' !== typeof exports && exports || new Function('return this')()));