{"action":"created","issue":{"url":"https://api.github.com/repos/ga-dc/project3/issues/63","labels_url":"https://api.github.com/repos/ga-dc/project3/issues/63/labels{/name}","comments_url":"https://api.github.com/repos/ga-dc/project3/issues/63/comments","events_url":"https://api.github.com/repos/ga-dc/project3/issues/63/events","html_url":"https://github.com/ga-dc/project3/issues/63","id":121130627,"number":63,"title":"returning from calling a series of asynchronous functions in a for loop","user":{"login":"solowt","id":10148145,"avatar_url":"https://avatars.githubusercontent.com/u/10148145?v=3","gravatar_id":"","url":"https://api.github.com/users/solowt","html_url":"https://github.com/solowt","followers_url":"https://api.github.com/users/solowt/followers","following_url":"https://api.github.com/users/solowt/following{/other_user}","gists_url":"https://api.github.com/users/solowt/gists{/gist_id}","starred_url":"https://api.github.com/users/solowt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solowt/subscriptions","organizations_url":"https://api.github.com/users/solowt/orgs","repos_url":"https://api.github.com/users/solowt/repos","events_url":"https://api.github.com/users/solowt/events{/privacy}","received_events_url":"https://api.github.com/users/solowt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-12-09T00:10:01Z","updated_at":"2015-12-09T01:46:50Z","closed_at":null,"body":"Part of our project relies on getting information about a user from github.\r\n\r\nOne of our functions takes a github user name and gets all repos on that user's profile.  The callback of that function contains a for loop that makes another call to github based on each repo name.  In this for loop we construct an object, and when all the calls have returned from github, the object is complete.\r\n\r\nThe issue we're having is that we don't know how to return this object when every one of the inner calls is finished.  We're able to print it, or save it to our database, but what we'd really like to do is return that object or chain another promise onto the inner function so we can do the subsequent task only when the object is complete.\r\n\r\nSome pseudo code of what we have right now:\r\n\r\n```js\r\nfunction getMsgs(user){\r\n   getAllRepos(user, function(err, res){\r\n      var counter = 0\r\n      var object = {}\r\n      for (var i = 0; i< res.length; i++) {\r\n         getCommitMessages(res[i], function(err, res) {\r\n             counter++\r\n             object.push(res)\r\n             if (counter == res.length) {\r\n                   console.log(object);\r\n             }   \r\n         })\r\n      }\r\n   })\r\n}\r\n\r\n```\r\n\r\nAny suggestions or guidance about how to refactor this would be really helpful."},"comment":{"url":"https://api.github.com/repos/ga-dc/project3/issues/comments/163080030","html_url":"https://github.com/ga-dc/project3/issues/63#issuecomment-163080030","issue_url":"https://api.github.com/repos/ga-dc/project3/issues/63","id":163080030,"user":{"login":"RobertAKARobin","id":6268177,"avatar_url":"https://avatars.githubusercontent.com/u/6268177?v=3","gravatar_id":"","url":"https://api.github.com/users/RobertAKARobin","html_url":"https://github.com/RobertAKARobin","followers_url":"https://api.github.com/users/RobertAKARobin/followers","following_url":"https://api.github.com/users/RobertAKARobin/following{/other_user}","gists_url":"https://api.github.com/users/RobertAKARobin/gists{/gist_id}","starred_url":"https://api.github.com/users/RobertAKARobin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RobertAKARobin/subscriptions","organizations_url":"https://api.github.com/users/RobertAKARobin/orgs","repos_url":"https://api.github.com/users/RobertAKARobin/repos","events_url":"https://api.github.com/users/RobertAKARobin/events{/privacy}","received_events_url":"https://api.github.com/users/RobertAKARobin/received_events","type":"User","site_admin":false},"created_at":"2015-12-09T01:46:50Z","updated_at":"2015-12-09T01:46:50Z","body":"Yup."}}