我有4个方法,每个返回一个承诺,我有他们的链结构。但是我不能在第一个Promise中有条件满足,所以在这种情况下,我需要/不应该在链中执行剩余的Promise。我怎样才能做到这一点?在链接的承诺,如果第一个承诺要求不执行其余的承诺,如何
这里是正在完成
任务1中的4个任务)使用,看看是否在蒙戈存在的数据,如果不
任务2)调用SOAP服务
任务3)从SOAP结果,操纵数据
任务4)把这个文档中蒙戈
这工作得很好,但是当任务1有数据,那么I S不能处理接下来的3个承诺(任务2,3,4)。
这里是我当前的代码
checkMongoForData(req, res)
.then(function (result) {
return makeTheSOAPcall(req, res, result)
.then(function (result) {
return fillTheReasonDescriptions(req, res, result);
})
.then(function (result) {
return upsertTheRespDocInMongo(req, res, result);
})
.then(function (result) {
res.status(200);
res.send({result: 'success', status: 200});
})
.catch(function (reject) {
res.status(reject.status);
res.send({result: reject.description, status: reject.status});
});
//我的功能定义是这样的
function checkMongoForData(req, res) {
return new Promise(function (resolve, reject) {
// TODO : the logic goes here
/// check to see for the data. If not there then continue
// if there is data, no need to do remaining tasks
});
}
如何实现这一目标?谢谢。
如果有数据,调用'拒绝()'。 – 2016-09-27 11:57:50
在这种情况下,如果您的条件得到满足(您会收到您需要的数据),请执行您的任务,并解决或拒绝未解决的链接承诺。 – Redu
你可以提供更多关于你想要做什么的信息吗?我在想你的设计可能存在一些缺陷。 – bflemi3