Bluebird: Promisifying API with existing 'Async'-suffixed method

Created on 30 Aug 2018  路  7Comments  路  Source: petkaantonov/bluebird

Currently, the promisifying methods throws an exception if the target contains a method with the same suffix being used.

The former behaviour would append the suffix anyway, with the only downside of having to use double 'Async', for example, when calling that specific method.

The solution would be specifying a different suffix but that may cause huge impact in big code bases.

What I would suggest is adding an option when promisifying, to ignore this check and append the suffix regardless. The code would still throw an exception if this option is not provided, so the user is aware of potential problems.

Most helpful comment

Are you using aws-sdk in your project? a temp fix is to downgrade to 2.245.1. This did the job for me today as I was on 2.305

All 7 comments

Are you using aws-sdk in your project? a temp fix is to downgrade to 2.245.1. This did the job for me today as I was on 2.305

2.304 is the latest version without the onAsync function

For reference, here is the issue on the aws-sdk repo: aws/aws-sdk-js#2229

I am facing this similar issue when using with Google Cloud sdk's storage package

Version of Google Cloud Storage - 2.3.4
Version of Bluebird being used - 3.5.3

can anyone please help me with this

Is there an option to simply not promisify routines that already have an Async suffix?

This error comes only when promisifying a method would overwrite some other original method on the object. For example the object has original methods .on()and .onAsync(), the promisified version of .on() would be .onAsync() which would overwrite the original .onAsync(). That's where the error comes from. For such objects you need to choose different suffix that will not conflict and result in overwriting any original methods.

Alternatively you can pass a filtering function to promisifyAll that disqualifies the offending methods from being promisified to resolve the conflict. See docs http://bluebirdjs.com/docs/api/promise.promisifyall.html

Promise.promisifyAll(api, {
    filter(name, _, __, passesDefaultFilter) {
        return passesDefaultFilter && name !== "on"
    }
})
Was this page helpful?
0 / 5 - 0 ratings

Related issues

popod picture popod  路  4Comments

icodeforlove picture icodeforlove  路  3Comments

chrisprobst picture chrisprobst  路  5Comments

julien-f picture julien-f  路  5Comments

srguiwiz picture srguiwiz  路  6Comments