我读到 promise 连接已被弃用 http://bluebirdjs.com/docs/api/promise.join.html
我的问题是
- 我应该如何更改此代码以 promise 所有,以及是否有更好 编写此代码的方法(代码正在运行!),但我想得到您的反馈,但代码应该具有与下面相同的逻辑
- 有一个使用 bluebird 来连接 js 的工具,它可以跟踪我是否有未完成的 promise 链
createProc = function (fPath) {
"use strict";
return Promise.join(
fs.readFileAsync(fPath, 'utf8')
.then(function (content) {
return parseFile(content).getWeb();
}),
scan.findInUseAsync(12, 152, 'localhost')
.then(envOptions.mod.bind(null, process.env))
).then(function (args) {
return inter.Process('run', args[0], args[1]);
}).then(function (result) {
return result.stdout;
}, function (error) {
return error;
});
};
最佳答案
如果你想切换到 Promise.all()
,它只接受一个 Promise 数组作为参数,并且不接受回调(你无论如何也不会使用它)。因此,您所要做的就是将您传递的两个 Promise 包装在一个数组中:
createProc = function (fPath) {
"use strict";
return Promise.all([
// added here ^
fs.readFileAsync(fPath, 'utf8')
.then(function (content) {
return parseFile(content).getWeb();
}),
scan.findInUseAsync(12, 152, 'localhost')
.then(envOptions.mod.bind(null, process.env))
]).then(function (args) {
return inter.Process('run', args[0], args[1]);
}).then(function (result) {
return result.stdout;
}, function (error) {
return error;
});
};
关于javascript - promise 加入变革 promise 一切,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34513640/