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