Skip to content

Commit

Permalink
Merge fb45cd4 into 424ed9b
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredkam committed Oct 7, 2014
2 parents 424ed9b + fb45cd4 commit f308df8
Showing 1 changed file with 12 additions and 8 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

0 comments on commit f308df8

Please sign in to comment.