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

Added .any() to kew, with tests and docs #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ketanbhatt
Copy link

nodeunit gives an implicit error because promise.reject expects an "error" as argument, and .any(), when all promises fail, give "array of errors" to promise.reject.

All tests pass, and tried it on the project i needed it for, all working.

@nicks
Copy link
Contributor

nicks commented Jul 15, 2015

thanks for the contribution! could you fill out a cla?
https://github.com/Medium/opensource/blob/master/sign-cla.md

} else {
promises[i].then(replaceEl.bind(null, output, 0))
.then(function resolveFirstPromise() {
promise.resolve(output[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you need a guard here if the promise has already been resolved?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry, but I didn't understand that.
When a promise resolves, my "finished" becomes true and i break out of loop.

What do you mean by guard and where? I took cue (read copied) from the allInternal function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have a race condition. resolveFirstPromise happens asynchronously,
after the loop has finished.

On Wed, Jul 15, 2015 at 1:47 PM, Ketan Bhatt [email protected]
wrote:

In kew.js #51 (comment):

  • var errorOutputs = []
  • var output = []
  • var finished = false
  • var promise = new Promise()
  • var counter = promises.length
  • for (var i = 0; i < promises.length; i += 1) {
  • if(finished) break;
  • if (!promises[i] || !isPromiseLike(promises[i])) {
  •  promise.resolve(promises[i]);
    
  •  break;
    
  • } else {
  •  promises[i].then(replaceEl.bind(null, output, 0))
    
  •  .then(function resolveFirstPromise() {
    
  •        promise.resolve(output[0]);
    

Hi, sorry, but I didn't understand that.
When a promise resolves, my "finished" becomes true and i break out of
loop.

What do you mean by guard and where? I took cue (read copied) from the
allInternal function.


Reply to this email directly or view it on GitHub
https://github.com/Medium/kew/pull/51/files#r34707149.

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

Successfully merging this pull request may close these issues.

2 participants