Namespace: pickSeries

async.pickSeries

Source:

Examples

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