wrapper.js
function wrapAsyncMethod(fn, ctx) {
    return function() {
        // Obtain function arguments
        var args = [].slice.call(arguments);

        // Return a thunkified function that receives a done callback
        return new Promise(function(resolve, reject) {
            // Add a custom callback to provided args
            args.push(function(err, result) {
                // Failed?
                if (err) {
                    return reject(err);
                }

                // Success
                resolve(result);
            });

            // Call original function
            fn.apply(ctx, args);
        });
    };
}
function wrapAsyncMethod(fn, ctx) {
    return function() {
        // Obtain function arguments
        var args = [].slice.call(arguments);

        // Return a thunkified function that receives a done callback
        return new Promise(function(resolve, reject) {
            // Add a custom callback to provided args
            args.push(function(err, result) {
                // Failed?
                if (err) {
                    return reject(err);
                }

                // Success
                resolve(result);
            });

            // Call original function
            fn.apply(ctx, args);
        });
    };
}
function wrapAsyncMethod ( fn , ctx ) { return function ( ) { // Obtain function arguments var args = [ ] . slice . call ( arguments ) ; // Return a thunkified function that receives a done callback return new Promise ( function ( resolve , reject ) { // Add a custom callback to provided args args . push ( function ( err , result ) { // Failed? if ( err ) { return reject ( err ) ; } // Success resolve ( result ) ; } ) ; // Call original function fn . apply ( ctx , args ) ; } ) ; } ; }
Wrap async methods inside a promise
Wrap async methods inside a promise