-
Notifications
You must be signed in to change notification settings - Fork 419
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
Initial implementation of Promises.all? and Promise.any? class methods. #198
Conversation
composite = Promise.new do | ||
completed = promises.collect do |promise| | ||
promise.execute if promise.unscheduled? | ||
promise.wait |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about doing zip this way, but it seems to me this locks up a thread for no good reason (at least in some cases). Should be possible to do the same just with registering hooks and on_reject
/on_fulfil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably isn't the most efficient implementation. There is definitely room for refactoring once we nail down the API.
FYI new future/promise #176 contains efficient implementation of |
@pitr-ch Thank you! I saw your post that the #176 branch includes any/all. Since this functionality was requested by someone I met at RubyConf who wants to use our gem in production, I wanted to get his feedback on the proposed API. I'd like to hold off a couple of days and see if we can get some feedback before we make the final decision on this API. |
I liked |
I don't have strong opinions about |
The original request was for .any? and .all? methods. We added .none? and .one? methods for synergy with arrays, but didn't like that these methods supressed exceptions. So we decided to add only the requested methods and consider other methods in the future.
Initial implementation of Promises.all? and Promise.any? class methods.
A
Promise.all
method was originally proposed by @gdo in Issue #80. This request was later echoed by @dinshaw when he and I met at RubyConf 2014. @dinshaw provided spike code with tests indicating one possible implementation.This PR implements four aggregating methods:
all
,any
,none
, andone
that provide behavior based on the similarly-named methods in Ruby's Ennumerable module. It generalizes that behavior in anaggregate
method that could (potentially) be extended and enhanced.