Promise连接添加新的函数调用链

我试图加载和parsing一个文件,但是在调用两个函数时遇到了一些麻烦,并且返回了这个promise的结果。 我正在使用蓝鸟承诺。 以下代码按预期工作:

run = function (filePath) { return Promise.join( fs.readFileAsync(filePath, 'utf8') .then(parseFile.parse.bind(null, 'userKey')), users.getUsersAsync(usersObj) .then(users.modifyRec.bind(null, process.env.users)) ).then(function (args) { return runProc('run', args[0], args[1]); .... 

我已经将parseFile.parse函数分为两个方法, parseFile.parseparseFile.getPropparseFile.getProp应该从parseFile.parse获取输出,并返回在方法分解之前返回的parseFile.parse 。 这是我尝试使用这两个函数:

 run = function (filePath) { return Promise.join( fs.readFileAsync(filePath, 'utf8') .then(parseFile.parse.bind(null, 'userKey')) .then(parseFile.getProp.bind(null,'key')), users.getUsersAsync(usersObj) .then(users.modifyRec.bind(null, process.env.users)) ).then(function (args) { return runProc('run', args[0], args[1]); .... 

但它不工作。 我在这里做错了什么?

UPDATE

 var ymlParser = require('yamljs'); var ymlObj; parse = function ( data) { "use strict"; if (!ymlObj) { ymlObj = ymlParser.parse(data); } return ymlObj; }; getProcWeb = function () { return ymlObj.prop.web; }; module.exports = { parse: parse, getProp: getProp }; 

Promise.join不会返回一个数组,在你的情况下 – args []。 Promise.all将返回一个数组。

所以在你的情况下,你应该改变你的Promise.join语法

  Promise.join( fs.readFileAsync(filePath, 'utf8') .then(parseFile.parse.bind(null, 'userKey')) .then(parseFile.getProp.bind(null,'key')), users.getUsersAsync(usersObj) .then(users.modifyRec.bind(null, process.env.users)) ,function(argsOne,argsTwo){ return runProc('run', argsOne, argsTwo); })); 

或者使用Promise.all

  Promise.all([promise1, promise2]).then(function(args){ return runProc('run', args[0], args[1]); });