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