Aws-sdk-js: Is there a plan to completely move to promise style?

Created on 17 Jun 2017  路  7Comments  路  Source: aws/aws-sdk-js

To be able to do for example

await s3.copyObject(...)
// instead of 
await s3.copyObject(...).promise()

It won't change much from callback style

s3.copyObject(...).then(..).catch(..)
// instead of 
s3.copyObject(..., function(err, data){ ... })

Maybe with v3?

feature-request needs-major-version

Most helpful comment

Eg here's a mixin:

const Thenable = Promiseable => class Thenable extends Promiseable {
   then(resolve, reject) {
      return this.promise(resolve, reject);
   },

   ['catch']: function(reject) {
       return this.promise(v => v, reject);
   }
}

Might need to cache the promise too

All 7 comments

We wouldn't be able to make the change described in a backwards compatible way, since calling an operation without a callback returns a request object. I'll leave this open as a feature request with the "needs major version" label.

+1

@jeskew You totally can, if you return a thenable instead of a promise

Eg here's a mixin:

const Thenable = Promiseable => class Thenable extends Promiseable {
   then(resolve, reject) {
      return this.promise(resolve, reject);
   },

   ['catch']: function(reject) {
       return this.promise(v => v, reject);
   }
}

Might need to cache the promise too

This is what knex does http://knexjs.org/#Interfaces-then

@caub

This feature is introduced in JS-SDK-V3 which is not GA yet but it might be a good start for you to try.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

Was this page helpful?
0 / 5 - 0 ratings