Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise.any? #15

Closed
andrewwakeling opened this issue Sep 28, 2015 · 7 comments
Closed

Promise.any? #15

andrewwakeling opened this issue Sep 28, 2015 · 7 comments

Comments

@andrewwakeling
Copy link
Contributor

It's desirable for me to have Promise.any. (i.e. If any promise resolves, then resolve).

Is it possible to create this method using the existing methods in Yaku? (e.g. I could do something similar to https://github.com/andyjansson/promise-any/blob/master/index.js ).

Is this a good idea? or should I wait for this functionality to appear in Yaku?

@ysmood
Copy link
Owner

ysmood commented Sep 28, 2015

I think you mean "Promise.race". Yaku supports it by default. The race function is ES6 standard method, you should use it over the non-standard any function.
https://github.com/ysmood/yaku#yakuraceiterable

@andrewwakeling
Copy link
Contributor Author

It's different.

Promise.any will resolve if any of the supplied promises resolve. It will only reject, if all of the promises reject.

@ysmood
Copy link
Owner

ysmood commented Sep 29, 2015

Well, I understand. How about add it to the yuku's utils namespace?

ysmood added a commit that referenced this issue Sep 29, 2015
@ysmood
Copy link
Owner

ysmood commented Sep 29, 2015

If you are interested in the ef23611, please make a pull request for it and fix the TODOs.

ysmood added a commit that referenced this issue Sep 30, 2015
ysmood added a commit that referenced this issue Sep 30, 2015
ysmood added a commit that referenced this issue Sep 30, 2015
@benjamingr
Copy link

Promise.race is very broken in that it will create a promise that pends forever with Promise.race([]) which is hard to debug.

In addition, if one promise rejects all the other rejections will go unhandled and unreported with .race, with .any we have the chance to return an iteration over all rejections (a promise for one, anyway).

Basically, you have a chance to provide a better API with .any.

ysmood added a commit that referenced this issue Oct 10, 2015
@ysmood
Copy link
Owner

ysmood commented Oct 10, 2015

Added, and it supports iterable by default.

Now all the function of yaku that handles array supports iterable.

@ysmood ysmood closed this as completed Oct 10, 2015
@andrewwakeling
Copy link
Contributor Author

Thanks for implementing this so promptly! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants