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。 这是实际发生的事情吗?
不, doneCallback
在return
之前发生,因为doneCallback
的结果是函数的返回值。 每调用一次doneCallback
将被调用一次。
- Node + Sequelize:如何在添加之前检查项目是否存在? (asynchronous混淆)
- 为什么瀑布和series / parallelLimit(1)之间的async.js不一致?
- 将数组传递给asynchronous库eachSeries – 期望Dictionary <{}>'
- 在node.js中依次运行多个asynchronous函数
- 使用asynchronous瀑布填充查询选项
- async.each在完成所有迭代后callback
- MEAN 2多租户(多个集合保存相互参考)
- 节点asynchronous – 工作asynchronous方法在async.parallel内返回undefined
- 我如何pipe理Node.jsasynchronousvariables作用域?