benjamingr / bluebird-api

Bluebird compatible API on top of native promises.
MIT License
37 stars 17 forks source link

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

Open MadaraUchiha opened 7 years ago

MadaraUchiha commented 7 years ago

goodnessSquad

benjamingr commented 7 years ago

k

MadaraUchiha commented 7 years ago

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 () => {})());

itaysabato commented 7 years ago

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!

MadaraUchiha commented 7 years ago

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.

itaysabato commented 7 years ago

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...

benjamingr commented 7 years ago

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

itaysabato commented 7 years ago

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.

benjamingr commented 7 years ago

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

However, I have to say chances are pretty slim.

itaysabato commented 7 years ago

@benjamingr OK then. Thanks a lot anyway!

benjamingr commented 7 years ago

@itaysabato sure, and sorry for losing :)