Permalink
Browse files

Refactor findAndLoad a tiny bit

  • Loading branch information...
maritz committed Dec 4, 2012
1 parent b853a28 commit 5a86ba1fbc95144c5c6d14d06b3abaced86dd453
Showing with 12 additions and 8 deletions.
  1. +12 −8 lib/retrieve.js
View
@@ -76,14 +76,18 @@ exports.load = function (id, callback) {
exports.findAndLoad = function findAndLoad(searches, callback) {
var self = this;
this.find(searches, function (err, ids) {
- if (err) callback(err, ids);
- if (ids.length == 0) callback("not found", ids);
- if (ids.length > 0) {
- async.map(ids, function (id, done) {
- self.load(id, function (err, props) {
- done(err, this);
- });
- }, callback);
+ if (err) {
+ callback(err, ids);
+ } else if (ids.length === 0) {
+ callback("not found", ids);
+ } else {
+ if (ids.length > 0) {
+ async.map(ids, function (id, done) {
+ self.load(id, function (err) {
+ done(err, self);
+ });
+ }, callback);
+ }
}
});
};

0 comments on commit 5a86ba1

Please sign in to comment.