- Source:
Examples
// array
var order = [];
var array = [1, 5, 3, 4, 2];
var iterator = function(num, done) {
setTimeout(function() {
order.push(num);
done(null, num % 2);
}, num * 10);
};
async.everyLimit(array, 2, iterator, function(err, res) {
console.log(res); // false
console.log(order); // [1, 3, 5, 2]
});
// array with index
var order = [];
var array = [1, 5, 3, 4, 2];
var iterator = function(num, index, done) {
setTimeout(function() {
order.push([num, index]);
done(null, num % 2);
}, num * 10);
};
async.everyLimit(array, 2, iterator, function(err, res) {
console.log(res); // false
console.log(order); // [[1, 0], [3, 2], [5, 1], [2, 4]]
});
// object
var order = [];
var object = { a: 1, b: 5, c: 3, d: 4, e: 2 };
var iterator = function(num, done) {
setTimeout(function() {
order.push(num);
done(null, num % 2);
}, num * 10);
};
async.everyLimit(object, 2, iterator, function(err, res) {
console.log(res); // false
console.log(order); // [1, 3, 5, 2]
});
// object with key
var order = [];
var object = { a: 1, b: 5, c: 3, d: 4, e: 2 };
var iterator = function(num, key, done) {
setTimeout(function() {
order.push([num, key]);
done(null, num % 2);
}, num * 10);
};
async.everyLimit(object, 2, iterator, function(err, res) {
console.log(res); // false
console.log(order); // [[1, 'a'], [3, 'c'], [5, 'b'], [2, 'e']]
});