我有两个由Bluebird运行的任务:
// Require bluebird...
var Promise = require("bluebird");
// Run two tasks together
Promise
.all([Git.getRemotes(), GitFtp.getFtpRemotes()])
.spread(function (remotes, ftpRemotes) {
// Something cool
});
q.js 我收到了回复:
remotes.value (the response of my task)
remotes.state ("fullfilled" or "rejected" depending if the task thrown an error or not)
ftpRemotes.value
ftpRemotes.state
因此,在spread()
部分内,我能够检查每项任务的状态
This is the code I was using before Bluebird
蓝鸟我得到了:
remotes
ftpRemotes
仅包含我的任务生成的数组。
我认为我需要Promise.allSettled
,但我无法在文档中找到它。
如何获得每项任务的状态?
答案 0 :(得分:7)
如果你想处理这个案子他们一起好/坏:
//Require bluebird...
var Promise = require("bluebird");
// Run two tasks together
Promise
.all([Git.getRemotes(), GitFtp.getFtpRemotes()])
.spread(function (remotes, ftpRemotes) {
// Something cool
}).catch(function(err){
// handle errors on both
});
如果您想要同时解决或拒绝使用Promise.settle
:
Promise
.settle([Git.getRemotes(), GitFtp.getFtpRemotes()])
.spread(function(remotesStatus,ftpRemoteStatus){
// the two are PromiseInspection objects and have:
// isFullfilled, isRejected, value() etc.
});