Permalink
Browse files

fix: fix #34, Model.count 的时候,在 callback 函数里面 throw Error 会触发两次 callback

 该段代码会被多次触发
  • Loading branch information...
XadillaX committed Jan 17, 2016
1 parent 57daa41 commit e567060fca2d90abe00d014cb049950bdf1fc934
Showing with 6 additions and 6 deletions.
  1. +6 −6 lib/query.js
@@ -714,13 +714,13 @@ Query.prototype.count = function(callback) {
return promisor._onExecuteResult(err);
}

try {
callback(undefined, result[0]["COUNT(0)"]);
promisor._onExecuteResult(undefined, result[0]["COUNT(0)"]);
} catch(e) {
callback(undefined, 0);
promisor._onExecuteResult(undefined, 0);
var count = 0;
if(result && result[0]) {
count = parseInt(result[0]["COUNT(0)"]) || 0;
}

callback(undefined, result[0]["COUNT(0)"]);
promisor._onExecuteResult(undefined, result[0]["COUNT(0)"]);
});

return promisor;

0 comments on commit e567060

Please sign in to comment.