当条件不满足时打破承诺链

时间:2017-05-04 11:49:15

标签: javascript es6-promise

嗨,我想做一件简单的事情,当条件不满足时,不要去第3个。我知道我可以通过放置一个break语句来抛出错误,但这不是处理这个问题的正确方法,所以我试着从外面调用另一个函数来阻止它没有成功:



Promise.resolve("hello")
.then((value)=> { return value})
.then(param=> {
	if(typeof(param) === "number"){
  	console.log(param)
    return
  }else{
  	console.log("I'll be stuck here")
    return outside()
  }
})

.then(()=>{
	console.log("inside 3rd promise")
})

function outside(){
	console.log("I'm outside")
  
}




0 个答案:

没有答案
相关问题