Created
June 22, 2014 08:39
-
-
Save mpj/6d0ac52212a5da3da1e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var findToArray = function(collection, query) { | |
var deferred = Q.defer(); | |
var cursor = collection.find(query); | |
collection.find({}).toArray(function(error, result) { | |
if (error) | |
deferred.reject(error) | |
else | |
deferred.resolve(result) | |
}) | |
return deferred.promise | |
} | |
findToArray(collection, {}) | |
.then(function(result) { | |
_.map(result, function (job) { | |
return [job._id, job.resolved]: | |
}); | |
}) | |
.then(function(resultatetAvMappen) { | |
// gör saker | |
}) | |
.fail(function(err) { | |
// hantera err - detta kan vara ett error i både map och find array | |
// väldigt trevligt att fel propagerar av sig själva och inte bara | |
// försvinner som i node | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment