我想保留错误func()
reject
,而不是直接onError()
选择,
之前我总是让func()
resolve
,然后确定返回结果yield func()
,
如果我想直接onError()
使用throw ..;
想知道任何更好的想法我可以让func()
reject
但决定之后yield func()
,直接onError()
或不
co(function* () {
yield func();
// if reject catch here, not direct to onError
yield func();
// if reject don't catch here just direct to onError
}).then(function (response) {
response = JSON.stringify(response);
res.send(response);
}, function (err) {
onError(err);
});
// ...
func: function() {
return new Promise(function (resolve, reject){
...
reject();
});
},