Skip to content

Commit

Permalink
Merge pull request #7 from alfredkam/master
Browse files Browse the repository at this point in the history
fixed each's inner property sync / async issue
  • Loading branch information
zerious committed Oct 7, 2014
2 parents 424ed9b + 59bebed commit 6134c16
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions lib/Model.js
Expand Up @@ -72,15 +72,19 @@ var Model = module.exports = Class.extend({

each: function each(options, callback) {
var then;
this.db.find(this, options, function (err, results) {
if (err) throw err;
if (results.length) {
results.forEach(callback);
}
if (then) {
then();
}
var self = this;
setImmediate(function () {
self.db.find(self, options, function (err, results) {
if (err) throw err;
if (results.length) {
results.forEach(callback);
}
if (then) {
then();
}
});
});

// TODO: Implement real promises.
return {then: function (callback) { then = callback; }};
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ormy",
"version": "0.2.2",
"version": "0.2.3",
"description": "Easy data models",
"dependencies": {
"mysql": "2.4.2",
Expand Down

0 comments on commit 6134c16

Please sign in to comment.