{"action":"created","comment":{"url":"https://api.github.com/repos/kriskowal/q/pulls/comments/24828387","id":24828387,"diff_hunk":"@@ -1540,6 +1540,56 @@ Promise.prototype.all = function () {\n };\n \n /**\n+ * Returns the first resolved promise of an array. Prior rejected promises are\n+ * ignored.  Rejects only if all promises are rejected.\n+ * @param {Array*} an array containing values or promises for values\n+ * @returns a promise fulfilled with the value of the first resolved promise,\n+ * or a rejected promise if all promises are rejected.\n+ */\n+Q.any = any;\n+\n+function any(promises) {\n+    var deferred = Q.defer();\n+    if (promises.length === 0) {\n+        return Q.resolve();\n+    }\n+\n+    var promisesCount = promises.length;\n+    for (var i = 0; i < promises.length; i++) {\n+        var promise = promises[i];\n+        /* Let's define that false could be a value to resolve with, so let's not\n+         * if(!promise)\n+         */\n+        if (promise === undefined || promise === null) {\n+            promisesCount--;\n+            continue;\n+        }\n+\n+        (function(promise, i) {\n+            Q.resolve(promise).then(function(result) {\n+                deferred.resolve(result);\n+            }, function(reason) {\n+                promisesCount--;\n+                if(promisesCount === 0) {\n+                    deferred.reject(new Error(\"No promises resolved successfully.\"));\n+                }\n+            }, function(progress) {\n+                deferred.notify({\n+                    index: i,\n+                    value: progress\n+                });\n+            });\n+        })(promise, i);\n+    }","path":"q.js","position":44,"original_position":44,"commit_id":"9df7841107f051da9dd42d275772f7f9125ba856","original_commit_id":"9df7841107f051da9dd42d275772f7f9125ba856","user":{"login":"kriskowal","id":60294,"avatar_url":"https://avatars.githubusercontent.com/u/60294?v=3","gravatar_id":"","url":"https://api.github.com/users/kriskowal","html_url":"https://github.com/kriskowal","followers_url":"https://api.github.com/users/kriskowal/followers","following_url":"https://api.github.com/users/kriskowal/following{/other_user}","gists_url":"https://api.github.com/users/kriskowal/gists{/gist_id}","starred_url":"https://api.github.com/users/kriskowal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kriskowal/subscriptions","organizations_url":"https://api.github.com/users/kriskowal/orgs","repos_url":"https://api.github.com/users/kriskowal/repos","events_url":"https://api.github.com/users/kriskowal/events{/privacy}","received_events_url":"https://api.github.com/users/kriskowal/received_events","type":"User","site_admin":false},"body":"You can use array_reduce as above in Q.all, especially since you need a closure to capture the index regardless.","created_at":"2015-02-17T16:26:57Z","updated_at":"2015-02-17T16:26:57Z","html_url":"https://github.com/kriskowal/q/pull/649#discussion_r24828387","pull_request_url":"https://api.github.com/repos/kriskowal/q/pulls/649","_links":{"self":{"href":"https://api.github.com/repos/kriskowal/q/pulls/comments/24828387"},"html":{"href":"https://github.com/kriskowal/q/pull/649#discussion_r24828387"},"pull_request":{"href":"https://api.github.com/repos/kriskowal/q/pulls/649"}}},"pull_request":{"url":"https://api.github.com/repos/kriskowal/q/pulls/649","id":29422277,"html_url":"https://github.com/kriskowal/q/pull/649","diff_url":"https://github.com/kriskowal/q/pull/649.diff","patch_url":"https://github.com/kriskowal/q/pull/649.patch","issue_url":"https://api.github.com/repos/kriskowal/q/issues/649","number":649,"state":"open","locked":false,"title":"Added Q.any(promisesArray) method.","user":{"login":"vergara","id":966936,"avatar_url":"https://avatars.githubusercontent.com/u/966936?v=3","gravatar_id":"","url":"https://api.github.com/users/vergara","html_url":"https://github.com/vergara","followers_url":"https://api.github.com/users/vergara/followers","following_url":"https://api.github.com/users/vergara/following{/other_user}","gists_url":"https://api.github.com/users/vergara/gists{/gist_id}","starred_url":"https://api.github.com/users/vergara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vergara/subscriptions","organizations_url":"https://api.github.com/users/vergara/orgs","repos_url":"https://api.github.com/users/vergara/repos","events_url":"https://api.github.com/users/vergara/events{/privacy}","received_events_url":"https://api.github.com/users/vergara/received_events","type":"User","site_admin":false},"body":"Returns a promise fulfilled with the value of the first resolved promise in promisesArray. If all promises in promisesArray are rejected, it returns a rejected promise.","created_at":"2015-02-17T07:13:22Z","updated_at":"2015-02-17T16:26:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"51c0af3a32c5050ca4563b27227e88af8d964429","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/kriskowal/q/pulls/649/commits","review_comments_url":"https://api.github.com/repos/kriskowal/q/pulls/649/comments","review_comment_url":"https://api.github.com/repos/kriskowal/q/pulls/comments/{number}","comments_url":"https://api.github.com/repos/kriskowal/q/issues/649/comments","statuses_url":"https://api.github.com/repos/kriskowal/q/statuses/9df7841107f051da9dd42d275772f7f9125ba856","head":{"label":"vergara:firstResolved","ref":"firstResolved","sha":"9df7841107f051da9dd42d275772f7f9125ba856","user":{"login":"vergara","id":966936,"avatar_url":"https://avatars.githubusercontent.com/u/966936?v=3","gravatar_id":"","url":"https://api.github.com/users/vergara","html_url":"https://github.com/vergara","followers_url":"https://api.github.com/users/vergara/followers","following_url":"https://api.github.com/users/vergara/following{/other_user}","gists_url":"https://api.github.com/users/vergara/gists{/gist_id}","starred_url":"https://api.github.com/users/vergara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vergara/subscriptions","organizations_url":"https://api.github.com/users/vergara/orgs","repos_url":"https://api.github.com/users/vergara/repos","events_url":"https://api.github.com/users/vergara/events{/privacy}","received_events_url":"https://api.github.com/users/vergara/received_events","type":"User","site_admin":false},"repo":{"id":30821365,"name":"q","full_name":"vergara/q","owner":{"login":"vergara","id":966936,"avatar_url":"https://avatars.githubusercontent.com/u/966936?v=3","gravatar_id":"","url":"https://api.github.com/users/vergara","html_url":"https://github.com/vergara","followers_url":"https://api.github.com/users/vergara/followers","following_url":"https://api.github.com/users/vergara/following{/other_user}","gists_url":"https://api.github.com/users/vergara/gists{/gist_id}","starred_url":"https://api.github.com/users/vergara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vergara/subscriptions","organizations_url":"https://api.github.com/users/vergara/orgs","repos_url":"https://api.github.com/users/vergara/repos","events_url":"https://api.github.com/users/vergara/events{/privacy}","received_events_url":"https://api.github.com/users/vergara/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vergara/q","description":"A tool for creating and composing asynchronous promises in JavaScript","fork":true,"url":"https://api.github.com/repos/vergara/q","forks_url":"https://api.github.com/repos/vergara/q/forks","keys_url":"https://api.github.com/repos/vergara/q/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vergara/q/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vergara/q/teams","hooks_url":"https://api.github.com/repos/vergara/q/hooks","issue_events_url":"https://api.github.com/repos/vergara/q/issues/events{/number}","events_url":"https://api.github.com/repos/vergara/q/events","assignees_url":"https://api.github.com/repos/vergara/q/assignees{/user}","branches_url":"https://api.github.com/repos/vergara/q/branches{/branch}","tags_url":"https://api.github.com/repos/vergara/q/tags","blobs_url":"https://api.github.com/repos/vergara/q/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vergara/q/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vergara/q/git/refs{/sha}","trees_url":"https://api.github.com/repos/vergara/q/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vergara/q/statuses/{sha}","languages_url":"https://api.github.com/repos/vergara/q/languages","stargazers_url":"https://api.github.com/repos/vergara/q/stargazers","contributors_url":"https://api.github.com/repos/vergara/q/contributors","subscribers_url":"https://api.github.com/repos/vergara/q/subscribers","subscription_url":"https://api.github.com/repos/vergara/q/subscription","commits_url":"https://api.github.com/repos/vergara/q/commits{/sha}","git_commits_url":"https://api.github.com/repos/vergara/q/git/commits{/sha}","comments_url":"https://api.github.com/repos/vergara/q/comments{/number}","issue_comment_url":"https://api.github.com/repos/vergara/q/issues/comments/{number}","contents_url":"https://api.github.com/repos/vergara/q/contents/{+path}","compare_url":"https://api.github.com/repos/vergara/q/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vergara/q/merges","archive_url":"https://api.github.com/repos/vergara/q/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vergara/q/downloads","issues_url":"https://api.github.com/repos/vergara/q/issues{/number}","pulls_url":"https://api.github.com/repos/vergara/q/pulls{/number}","milestones_url":"https://api.github.com/repos/vergara/q/milestones{/number}","notifications_url":"https://api.github.com/repos/vergara/q/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vergara/q/labels{/name}","releases_url":"https://api.github.com/repos/vergara/q/releases{/id}","created_at":"2015-02-15T07:46:50Z","updated_at":"2015-02-15T07:46:51Z","pushed_at":"2015-02-17T07:25:35Z","git_url":"git://github.com/vergara/q.git","ssh_url":"git@github.com:vergara/q.git","clone_url":"https://github.com/vergara/q.git","svn_url":"https://github.com/vergara/q","homepage":"http://documentup.com/kriskowal/q/","size":4572,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"v1"}},"base":{"label":"kriskowal:v1","ref":"v1","sha":"d37583b8b9479b2a25116088dfb9d5f20ce1f34b","user":{"login":"kriskowal","id":60294,"avatar_url":"https://avatars.githubusercontent.com/u/60294?v=3","gravatar_id":"","url":"https://api.github.com/users/kriskowal","html_url":"https://github.com/kriskowal","followers_url":"https://api.github.com/users/kriskowal/followers","following_url":"https://api.github.com/users/kriskowal/following{/other_user}","gists_url":"https://api.github.com/users/kriskowal/gists{/gist_id}","starred_url":"https://api.github.com/users/kriskowal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kriskowal/subscriptions","organizations_url":"https://api.github.com/users/kriskowal/orgs","repos_url":"https://api.github.com/users/kriskowal/repos","events_url":"https://api.github.com/users/kriskowal/events{/privacy}","received_events_url":"https://api.github.com/users/kriskowal/received_events","type":"User","site_admin":false},"repo":{"id":887025,"name":"q","full_name":"kriskowal/q","owner":{"login":"kriskowal","id":60294,"avatar_url":"https://avatars.githubusercontent.com/u/60294?v=3","gravatar_id":"","url":"https://api.github.com/users/kriskowal","html_url":"https://github.com/kriskowal","followers_url":"https://api.github.com/users/kriskowal/followers","following_url":"https://api.github.com/users/kriskowal/following{/other_user}","gists_url":"https://api.github.com/users/kriskowal/gists{/gist_id}","starred_url":"https://api.github.com/users/kriskowal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kriskowal/subscriptions","organizations_url":"https://api.github.com/users/kriskowal/orgs","repos_url":"https://api.github.com/users/kriskowal/repos","events_url":"https://api.github.com/users/kriskowal/events{/privacy}","received_events_url":"https://api.github.com/users/kriskowal/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kriskowal/q","description":"A tool for creating and composing asynchronous promises in JavaScript","fork":false,"url":"https://api.github.com/repos/kriskowal/q","forks_url":"https://api.github.com/repos/kriskowal/q/forks","keys_url":"https://api.github.com/repos/kriskowal/q/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kriskowal/q/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kriskowal/q/teams","hooks_url":"https://api.github.com/repos/kriskowal/q/hooks","issue_events_url":"https://api.github.com/repos/kriskowal/q/issues/events{/number}","events_url":"https://api.github.com/repos/kriskowal/q/events","assignees_url":"https://api.github.com/repos/kriskowal/q/assignees{/user}","branches_url":"https://api.github.com/repos/kriskowal/q/branches{/branch}","tags_url":"https://api.github.com/repos/kriskowal/q/tags","blobs_url":"https://api.github.com/repos/kriskowal/q/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kriskowal/q/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kriskowal/q/git/refs{/sha}","trees_url":"https://api.github.com/repos/kriskowal/q/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kriskowal/q/statuses/{sha}","languages_url":"https://api.github.com/repos/kriskowal/q/languages","stargazers_url":"https://api.github.com/repos/kriskowal/q/stargazers","contributors_url":"https://api.github.com/repos/kriskowal/q/contributors","subscribers_url":"https://api.github.com/repos/kriskowal/q/subscribers","subscription_url":"https://api.github.com/repos/kriskowal/q/subscription","commits_url":"https://api.github.com/repos/kriskowal/q/commits{/sha}","git_commits_url":"https://api.github.com/repos/kriskowal/q/git/commits{/sha}","comments_url":"https://api.github.com/repos/kriskowal/q/comments{/number}","issue_comment_url":"https://api.github.com/repos/kriskowal/q/issues/comments/{number}","contents_url":"https://api.github.com/repos/kriskowal/q/contents/{+path}","compare_url":"https://api.github.com/repos/kriskowal/q/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kriskowal/q/merges","archive_url":"https://api.github.com/repos/kriskowal/q/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kriskowal/q/downloads","issues_url":"https://api.github.com/repos/kriskowal/q/issues{/number}","pulls_url":"https://api.github.com/repos/kriskowal/q/pulls{/number}","milestones_url":"https://api.github.com/repos/kriskowal/q/milestones{/number}","notifications_url":"https://api.github.com/repos/kriskowal/q/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kriskowal/q/labels{/name}","releases_url":"https://api.github.com/repos/kriskowal/q/releases{/id}","created_at":"2010-09-04T01:21:12Z","updated_at":"2015-02-17T11:59:11Z","pushed_at":"2015-02-11T05:54:08Z","git_url":"git://github.com/kriskowal/q.git","ssh_url":"git@github.com:kriskowal/q.git","clone_url":"https://github.com/kriskowal/q.git","svn_url":"https://github.com/kriskowal/q","homepage":"http://documentup.com/kriskowal/q/","size":4572,"stargazers_count":7771,"watchers_count":7771,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":611,"mirror_url":null,"open_issues_count":66,"forks":611,"open_issues":66,"watchers":7771,"default_branch":"v1"}},"_links":{"self":{"href":"https://api.github.com/repos/kriskowal/q/pulls/649"},"html":{"href":"https://github.com/kriskowal/q/pull/649"},"issue":{"href":"https://api.github.com/repos/kriskowal/q/issues/649"},"comments":{"href":"https://api.github.com/repos/kriskowal/q/issues/649/comments"},"review_comments":{"href":"https://api.github.com/repos/kriskowal/q/pulls/649/comments"},"review_comment":{"href":"https://api.github.com/repos/kriskowal/q/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/kriskowal/q/pulls/649/commits"},"statuses":{"href":"https://api.github.com/repos/kriskowal/q/statuses/9df7841107f051da9dd42d275772f7f9125ba856"}}}}