1
的基础上调用Q无极下面是我的病情条件逻辑
if abc is true
call async func1, func2
else
call async func1
function test(): Q.Promise<boolean> {
if(abc)
Q.all([func1,func2])
else
Q.all([func1])
//if failed throw reject reason all the way in the chain
}
- 如图所示,它可以使用
if
和else
条款来完成,有没有更好的方式来有条件地承诺? - 如何丢回
error from any one of the promises
?
如果其中一个'promise'被“拒绝”会怎么样,并且我会如何一直向上抛出该“错误”。我试图学习'Q.promises',所以如果这是个愚蠢的问题,请原谅:) – Reddy
你不需要明确地抛出。如果其中一个函数抛出或返回被拒绝的promise,那么'Q.all'也会拒绝你,并且错误会自动冒泡到Q.all错误处理器:'test()。then(function(){console.log('所有罚款')})。catch(function(error){console.log('something went wrong')})'。 – dfsq