bluebird-api icon indicating copy to clipboard operation
bluebird-api copied to clipboard

Promise.map(), Promise.filter(), etc. return native Promises instead of Bluebird

Open MadaraUchiha opened this issue 7 years ago • 10 comments

#goodnessSquad

MadaraUchiha avatar May 10 '17 18:05 MadaraUchiha

k

benjamingr avatar May 13 '17 16:05 benjamingr

What you did won't do. As long as an async function returns a native Promise, you need to wrap the whole thing with return Bluebird.resolve((async () => {})());

MadaraUchiha avatar May 13 '17 16:05 MadaraUchiha

Hey there :)

This project looks very promising - nice work! I have a couple of questions, if you may:

  1. When this issue is resolved, async functions will return the bluebird-api version of native promises?
  2. If so, will it be possible to use the bluebird cancel() API in conjunction with async functions?

Thanks!

itaysabato avatar Aug 04 '17 13:08 itaysabato

No to both. Sadly, as it currently stands, async functions always return native promises, that's why there's a return Bluebird.resolve() around every function implementation.

MadaraUchiha avatar Aug 04 '17 13:08 MadaraUchiha

I see. So there is actually no practical way to use cancellations with native async functions in node?

It would have been really nice if there was a way to monkeypatch native promises to support these kinds of things that will probably never make it to ECMAScript...

itaysabato avatar Aug 05 '17 09:08 itaysabato

There was a proposal that allowed this - it was rejected (compositional functions)

There was another proposal that allowed this (cancellable promise) which was also rejected.

Sorry - the good people of th TC don't like these proposals very much - and the sad truth is that there is politics involved.

On the other hand, you can manually use tokens

benjamingr avatar Aug 05 '17 12:08 benjamingr

I don't care very much for tokens - I started using them when I thought the proposal will be accepted but once it was dropped I decided to go back to bluebird-style cancel which is a much better approach in my eyes.

The question is: is it possible that node will ever provide its own hooks for extending promises, regardless of the ECMAScript standard? It seems like a pretty simple then interceptor would enable one to implement custom cancellations.

itaysabato avatar Aug 05 '17 12:08 itaysabato

@itsysabato - we can discuss this at Node - if you have a concrete proposal.

However, I have to say chances are pretty slim.

benjamingr avatar Aug 05 '17 12:08 benjamingr

@benjamingr OK then. Thanks a lot anyway!

itaysabato avatar Aug 05 '17 13:08 itaysabato

@itaysabato sure, and sorry for losing :)

benjamingr avatar Aug 05 '17 13:08 benjamingr