You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
doushio/tail.js

29 lines
588 B

// avoids stack overflow for long lists
exports.forEach = function (array, func, callback) {
step(0);
function step(i) {
if (i >= array.length)
return callback(null);
func(array[i], function (err) {
if (err)
return callback(err);
setImmediate(step, i + 1);
});
}
};
exports.map = function (array, func, callback) {
var results = [];
step(0);
function step(i) {
if (i >= array.length)
return callback(null, results);
func(array[i], function (err, res) {
if (err)
return callback(err);
results.push(res);
setImmediate(step, i + 1);
});
}
};