Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
Is there a way to make main code wait for a nested fetch?

I am working on a Slack bot that fetches merge requests for given list of repositories (so multiple).

const fetchRepositories = (repositories) => {
    return repositories.reduce(async (accumulator, currentRepository) => {
        const eligibleMRs = await fetchEligibleMergeRequests(currentRepository.api);
        // the PROBLEM is here
        const refinedMRs = eligibleMRs.length && eligibleMRs.map(mr => {
            // some logic to clean the shorten info received
        }

        return Promise.resolve(accumulator)
            .then(...) //return personalized object for each repository
    }, []);
};

The problem is that eligibleMRs is an array of Promise { <pending> } (each merge request).

And this problem appeared when instead of only fetching all repository merge requests, I added another .then that fetches the list of reviewers for every mr.

const fetchEligibleMergeRequests = (url) => {
    return fetch(url, fetchOptions)
        .then(response => {
            return response.json();
        })
        .then(data => {
            return data.filter(mr => filterMergeRequest(mr));
            // when I only had this .then everything was perfect
        })
        .then(async filteredMRs => {
            return filteredMRs.map(async mr => {
                const fetchedReviewers = await fetchReviewers(mr["project_id"], mr.iid);
                //this fetch is another call to GitlabAPI in order to retrieve reviewers
                return Object.assign({}, mr, {
                    reviewers: fetchedReviewers
                });
            });
        })
};

What I would like to ask help for is the fact that the newly added fetch (the one that gets the reviewers for each mr) seems to hold everything back. And I would like to make the main code TO WAIT for reviewers fetching.

Thanks to all trying to help.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!