when/node liftAll not working on s3 object

218 Views Asked by At

I'm trying to lift all the functions in an Amazon S3 object using when/node.

var when = require('when');
var nodefn = require('when/node');
var AWS = require('aws-sdk');
var s3 = new AWS.S3();

var promisedS3 = nodefn.liftAll(s3);

when(promisedS3.listBuckets())
    .then(function(data) {
        console.log(data);
    })

However, it looks like a request object is being printed out. I'm kind of at a loss as to what is happening here, I can get the correct results if I individually lift functions like so:

var listBucketsP = nodefn.lift(s3.listBuckets.bind(s3));

Any ideas?

1

There are 1 best solutions below

0
On

Try this:

nodefn.liftAll(s3.__proto__, undefined, s3);

Then just do

s3.listBuckets().then(function(data) { 
    console.log(data); 
});

This worked for me.

Explanation: the methods you are trying to modify are not part of the s3 object itself, but of its prototype. When's node.liftAll's 3 argument version takes the source object first, an optional transformation function, and finally the destination object (to attach the lifted functions onto).

So we're taking the functions from the prototype and attach the promisified versions to the object we're working with.