When to use denodeify/nfbind vs nfcall/ninvoke

I'm working with Mongoose, and I'd like to use a promise approach with the Q library.

Not sure when to use the various methods nfcall,nfinvoke or wrap the APIs with denodeify/nfbind


var p = Q.when(User.findOne({login: 'johndoe'}).exec());

Or Something like:

Q.ninvoke(User, 'findOne', '{login:"johndoe"}').then(...)

Or wrapping the API like:

'use strict';

    //pUser.js Q/promise wrapper
    var Q = require('q'),
    mongoose = require('mongoose'),
    User = mongoose.model('User');

    exports.findOne = function() {
    return Q.denodefiy(User.findOne);

    //and then use like:
    var pUser = require('pUser');

    pUser.findOne({...}).then(function(user) { ... });

I've also seen approaches like this which wrap every method with an nfbind or something similar



Mongoose (at least in the last year or so) already returns promises that are Promises/A+ spec complaint.

You don't need to wrap them in Q promises unless you have to. Q, being promises/A+ complaint itself will gladly consume these promises and interop with them for you.

You can, for example use Q.all on three calls of find(...).exec().

     User.find({route: foo}).exec(), // Q will detect that the values are 'thenable'
     User.find({route: bar}).exec(), // and will automatically assimilate them into a 
     User.find({route: baz}).exec()  // Q promise on its own. No explicit action needed.
     // access results.

Need Your Help

Anyone know of a tool to convert SSRS (RDL) reports to Crystal Reports (RPT)?

sql crystal-reports reporting-services

I'm looking for a tool that will assist in the conversion from SSRS to Crystal. I've found numerous tools that will go the other way (From Crystal to SSRS), but none that will work for my specific ...

Eclipse is not working properly after update it

android eclipse eclipse-plugin

I have just updated my SDK. After the update, my eclipse does not work properly.