promises to the rescue! no need to worry. just play it
cool<https://github.com/kriskowal/q>.
Don't let those callbacks and error passing get you down! B)
var q = require('q');
// ncall takes the function, the scope, then optional arguments
q.ncall(db.open, db)
.then(function() {
return q.ncall(db.collection, db, 'collection name')
}).then(function(collection) {
// Example for what to do if you need conditional logic
if(!collection) {
return q.ncall(db.createCollection, db, 'colllection name');
}
}).then(function(collection) {
return q.ncall(db.query, db, collection, 'query');
}).then(function (queryResults) {
// I have query results! yay!!
console.log(queryResults);
}).fail(function(err) {
console.log('one of the above steps went irreversibly wrong!',
err);
});
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en