-
Notifications
You must be signed in to change notification settings - Fork 0
Homework #1
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
base: master
Are you sure you want to change the base?
Homework #1
Conversation
webwin0
left a comment
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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)
webwin0
left a comment
There was a problem hiding this 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.
No description provided.