1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 1 | module.exports = { /** */ each: function(items, each, complete) { var total = items.length; var completed = 0; items.forEach(function(item) { var called = false; each(item, function() { if (called) throw new Error("callback called twice"); called = true; if (++completed === total && complete) complete(); }); }); } }; |