質問

I have the following code which uses async.js

var async = require('async');
var A = [];

for(var i = 1; i < 100; i++)
    A.push(i);

async.eachSeries(A, function(item) {
    console.log(item);
});

I expected this to print numbers from 1 to 100, however when I run this the output is just 1

If I use each() instead of eachSeries() it prints all the numbers, though.

So, why is the code not working while eachSeries() is just a serial version of each()?

役に立ちましたか?

解決

The iterator functions needs 2 arguments item and callback, callback must be called once the iteration is complete.

async.eachSeries(A, function(item, callback) {
    console.log(item);
    callback();
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top