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

139
Views
Promise pending on async function

I'm trying to get data from an API request but I don't know why await does not wait to get data to return value. Anyone can help me?

async function getChampionMasteryData(championId, summonerName) {  
    try {
        var summonerId = process.env.SUMMONER_ID;
        
        let championMasteryData = await axios(`https://euw1.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/${summonerId}/by-champion/${championId}?api_key=${process.env.API_KEY}`, {responseType: 'json'});

        return championMasteryData.data;
    } catch (e) {
        console.log(e);
    }
}

Output:

Promise { <pending> }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It's quite likely that you are not awaiting for the getChampionMasteryData function. You should call it like await getChampionMasteryData(championId, summonerName) instead of calling it directly.

If you want to call it from a non-async function, you can use then to wait until it resolves like below,

getChampionMasteryData(championId, summonerName).then((data) => {
    console.log(data);
});
about 4 years ago · Juan Pablo Isaza Report
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!