<分区>
我有一个类似于这个的代码:
promise_function().then(()=>{
//do something
return another_promise_fucntion();
}).then(() => {
//do something
return another_promise_function1();
}).then((result) => {
//check if result is valid
if(!result)
//break chain (how to stop calling the next .then functions ?)
else
return another_promise_function2();
}).then(()=>{
//do something
return another_promise_function3();
}).catch((err)=>{
//handle error
});
如果返回的结果无效,我想停止调用下一个 .then() 函数。
我使用了“throw new Error()”,它工作得很好,但我不确定这是否是推荐的方式。