我在两个具有相同回调函数的函数中使用 async.parallel
.在第二个函数 (two()
) 中添加了第三个函数作为加法函数
function one(){
var testuser = 1;
async.parallel([onefunction, secondfunction], function(err, result){...})
}
function two(){
var testuser = 2;
async.parallel([onefunction, secondfunction, thirdfunction], function(err, result){...})
}
function onefunction(callback){....code with testuser......}
function twofunction(callback){....code with testuser......}
function thirdfunction(callback){....code with testuser......}
问:如何访问 onefunction
、secondfunction
和 thirdfunction
中的 testuser 值。
现在我得到undefined err。我也试过作为正常的参数传递逻辑 onefunction(testuser)
,但它不起作用。
我想在多种情况下使用 onefunction
、twofunction
...我该怎么做?
最佳答案
正如@Felix 所建议的,
function one(){
var testuser = 1;
async.parallel([onefunction, secondfunction], function(err, result){...})
}
function two(){
var testuser = 2;
async.parallel([
callback => onefunction(testuser, callback),
callback => twofunction(testuser, callback),
callback => thirdfunction(testuser, callback)], function(err, result){...})
}
function onefunction(callback){....code with testuser......}
function twofunction(callback){....code with testuser......}
function thirdfunction(callback){....code with testuser......}
关于node.js - 如何复用异步回调函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37178464/