Get the promise of Bluebird from async features waiting

I am looking for a way, with Node v7.6 or higher, to get the Bluebird Promise (or any non-native promise) when an asynchronous function is called.

In the same way I can do:

global.Promise = require('Bluebird'); // Or Q/When
var getResolvedPromise = () => Promise.resolve('value');

getResolvedPromise
  .tap(...) // Bluebird method
  .then(...);

See: Can I use global.Promise = require ("bluebird")

I want to be able to do something like:

global.Promise = require('Bluebird'); // Or Q/When
var getResolvedAsyncAwaitPromise = async () => 'value';

getResolvedAsyncAwaitPromise()
  .tap(...) // Error ! Native Promises does not have `.tap(...)`
  .then(...);

I know that I can use something like:

Bluebird.resolve(getResolvedAsyncAwaitPromise())
  .tap(...);

But I was curious if there would be a way to change the default promise returned AsyncFunction. The constructor is as follows:

Note that AsyncFunction is not a global object. This can be obtained by evaluating the following code.

Object.getPrototypeOf(async function(){}).constructor

MDN link to AsyncFunction

AsyncFunction Promise, .

!

+6
1

, AsyncFunction

.

async function . , , - . , . native promises. , .

- :

getResolvedAsyncAwaitPromise().tap(...)

, Promise.method:

const Bluebird = require('Bluebird');
const getResolvedAsyncAwaitPromise = Bluebird.method(async () => 'value');

getResolvedAsyncAwaitPromise()
.tap(…) // Works!
.then(…);
+8

All Articles