为了始终从我的函数返回一个promise,我要么从api调用返回promise,要么生成一个deferred对象,然后拒绝它,然后返回它的承诺......
function listIssues(user, repository, filters) {
if (!user || !repository) {
// this seems a bit long winded, is there an easier way..?
var deferred = Q.defer();
var warning = helper.chalk.gray('You must specifiy user/organization and repository name...');
deferred.reject(warning);
return deferred.promise;
} else {
return api.getIssues(user, repository, filters);
}
}
有一条捷径可以一步完成所有这些吗?