Skip to content

Conversation

@mkhomytsya
Copy link
Owner

No description provided.

Copy link

@webwin0 webwin0 left a comment

Choose a reason for hiding this comment

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

package.json is missed

* @param {int} limit
*/
async function getContributors(organization, limit = 3) {
async function getContributorsOfReposByOwner(owner, repo) {
Copy link

Choose a reason for hiding this comment

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

Better to move this function outside

* @param {int} limit
*/
async function getContributors(organization, limit = 3) {
async function getContributorsOfReposByOwner(owner, repo) {
Copy link

Choose a reason for hiding this comment

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

async function everytime returns promise. Here await unpacks promise, but async packs value in promise.
More efficient return request

})).slice(0, limit);

for(i in repos) {
contributors[repos[i].name] = (await getContributorsOfReposByOwner(
Copy link

Choose a reason for hiding this comment

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

With await, we will wait when is finished a previous request to start next request.
You need to use Promise.all to make them parallelly.

const contributors = await Promis.all(repos.map(repo => ..))

allresult.map(([repo, contributorsOfReposByOwner]) => {
contributors[repo] = contributorsOfReposByOwner.map((data) => data.login);
});
resolve(contributors);
Copy link

Choose a reason for hiding this comment

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

resolve we can use when we work with the callbacks.
Here Promise chain and Promise.all is enough.

*/
function getContributors(organization, limit = 3) {
return new Promise(function(resolve) {
function getContributorsOfReposByOwner(owner, repo) {
Copy link

Choose a reason for hiding this comment

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

please move this function outside

"User-Agent": "request-promise"
}
}).then((repos) => {
Promise.all(repos.slice(0, limit).map((repo) => {
Copy link

Choose a reason for hiding this comment

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

You need to return Promise.all and then you can use .then((allresult) on the same level as .then((repos)

Copy link

@webwin0 webwin0 left a comment

Choose a reason for hiding this comment

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

Move getContributorsOfReposByOwner outside and refactor promise getContributors in 02_promise.js
You don't need new Promise there.

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.

3 participants