asynchronous与节点的JS

这个函数使用async.js库的进展是什么?

var async = require('async'); var square = function (num, doneCallback) { console.log(num * num); // Nothing went wrong, so callback with a null error. return doneCallback(null); }; // Square each number in the array [1, 2, 3, 4] async.each([1, 2, 3, 4], square, function (err) { // Square has been called on each of the numbers // so we're now done! console.log("Finished!"); }); 

在'square'函数中,return doneCallback(null)是每次传递一个新的数字时运行,还是在所有数字完成后运行?

我认为这是所有的数字已经通过和console.log'd运行,IMO返回将中断和停止function。 这是实际发生的事情吗?

不, doneCallbackreturn之前发生,因为doneCallback的结果是函数的返回值。 每调用一次doneCallback将被调用一次。