If I have a function that gets an api response and awaits it, like this:
async function getResponse(repo) {
const apiResponse = await axios.get(...); // uses repo
return apiResponse;
}
and I have a function that applies this function to many repos:
async function getResponsesMany(repos) {
const promises = [];
repos.forEach(repo => promises.push(getResponse(repo));
const responses = await Promise.all(promises);
return responses;
}
I can get all my data like this:
const allData = await getResponsesMany(myRepos);
But this is weird to me, because getResponse
is awaiting the axios.get
call, but I feel like I don't need to do that, since when I await Promise.all(promises)
it will handle any nested promises. Am I supposed to therefore refactor getResponse
to return the promise returned by axios.get
instead? Is there a reason one should be faster than the other?