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' 중 하나가'rejected'이고 어떻게'error'를 던지면 어떻게 될까요? 나는'.promises'를 배우려고하고있어, 바보 같은 질문이라면 실례합니다 :) – Reddy
당신은 명시 적으로 던질 필요가 없습니다. 함수 중 하나가 거부 된 약속을 던지거나 반환하면 'Q.all'도 자동으로 거부되며 오류는 자동으로 Qall 오류 처리기로 전달됩니다.'test(). then (function() {console.log (' 모두 괜찮아요.)}). catch (function (error) {console.log ('something went wrong')})'. – dfsq