Added .any() to kew, with tests and docs#51
Conversation
|
thanks for the contribution! could you fill out a cla? |
There was a problem hiding this comment.
i think you need a guard here if the promise has already been resolved?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
you have a race condition. resolveFirstPromise happens asynchronously,
after the loop has finished.
On Wed, Jul 15, 2015 at 1:47 PM, Ketan Bhatt notifications@github.com
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.
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.