[英]Add new parameter to promise all chain
I use the following code which is working as expected, Now I need to add the 我使用下面的代码可以正常工作,现在我需要添加
modifyOpt()
function,currently this is working and in the return I pass args[2] which is working, now I need add additional thing... I need to send the return (which is port) from portscanner.findAPortNotInUseAsync
also to modifyOpt()
, to be like modifyOpt(port)
How should I do that ? 函数,当前这是可行的,在返回中,我传递了args [2],它正在工作,现在我需要添加其他内容...我需要从portscanner.findAPortNotInUseAsync
发送返回值(即port)也要modifyOpt()
,就像modifyOpt(port)
我应该怎么做?
return Promise.all([
fs.readFileAsync(filePath, 'utf8').then(pars.getEx.bind(null, 'user')),
portscanner.findAPortNotInUseAsync(3000, 4000, 'localhost'),
modifyOpt()
]).then(function(args) {
return processExe('exec', args[0], args[1],args[2]);
})
Just chain the modifyOpt
after the portscanner.findAPortNotInUseAsync(…)
promise with then
to get the fulfillment value as a parameter. 刚刚链modifyOpt
后portscanner.findAPortNotInUseAsync(…)
与承诺then
得到履行值作为参数。
If you need to use its result twice, just pass the result two times to processExec
. 如果需要两次使用其结果,只需将结果两次传递给processExec
。
return Promise.all([
fs.readFileAsync(filePath, 'utf8').then(pars.getEx.bind(null, 'user')),
portscanner.findAPortNotInUseAsync(3000, 4000, 'localhost').then(modifyOpt)
]).then(function(args) {
return processExe('exec', args[0], args[1], args[1]);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.