【发布时间】:2016-09-14 13:36:35
【问题描述】:
在仅使用回调后尝试将我的代码移动到 Promise 时, (不破坏函数的界面)我遇到了一个问题。 在这样的代码示例中:
function callMeWithCallback(args, next) {
Promise.resolve()
.then(()=> {
return next("some error will be thrown here");
}).catch((error)=> {
return next("Error in callMeWithCallback func");
});
}
callMeWithCallback(args, function(){
throw "some error";
})
在callMeWithCallback func中解析promise并调用一次回调后,会抛出错误,代码返回callMeWithCallback函数中的catch并再次调用回调。
我希望 callMeWithCallback 函数只回调一次(无论是否发生错误)我需要进行哪些更改?
【问题讨论】:
标签: javascript node.js promise