promise.all map statement

//Here i have filmresponse.json() which will return promise so i uses promise.
//all otherwise it won't be possible to run it 

let characterResponse = await fetch('http://swapi.co/api/people/2/')
let characterResponseJson = await characterResponse.json()
let films = await Promise.all(
  characterResponseJson.films.map(async filmUrl => {
    let filmResponse = await fetch(filmUrl)
    return filmResponse.json()
  })
)
console.log(films)

3.9
10

                                    // Function to fetch Github info of a user.
const fetchGithubInfo = async (url) => {
  console.log(`Fetching ${url}`)
  const githubInfo = await axios(url) // API call to get user info from Github.
  return {
    name: githubInfo.data.name,
    bio: githubInfo.data.bio,
    repos: githubInfo.data.public_repos
  }
}

// Iterates all users and returns their Github info.
const fetchUserInfo = async (names) => {
  const requests = names.map((name) => {
    const url = `https://api.github.com/users/${name}`
    return fetchGithubInfo(url) // Async function that fetches the user info.
     .then((a) => {
      return a // Returns the user info.
      })
  })
  return Promise.all(requests) // Waiting for all the requests to get resolved.
}


fetchUserInfo(['sindresorhus', 'yyx990803', 'gaearon'])
 .then(a => console.log(JSON.stringify(a)))

/*
Output:
[{
  "name": "Sindre Sorhus",
  "bio": "Full-Time Open-Sourcerer ·· Maker ·· Into Swift and Node.js ",
  "repos": 996
}, {
  "name": "Evan You",
  "bio": "Creator of @vuejs, previously @meteor & @google",
  "repos": 151
}, {
  "name": "Dan Abramov",
  "bio": "Working on @reactjs. Co-author of Redux and Create React App. Building tools for humans.",
  "repos": 232
}]
*/

3.9 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
promise.all map statement map with promise.all promise.all array map all promise with map then all promise with map promise.all .map Promise.all inside array.map js use Promise.all inside a map in js promise.all with map inside array map promise all js map operation promise.all javascript promise all map results Promise.all with array map js promise all map results why to use promise.all if we map mapping all promises js promise.all array.map javascript promise all array map promise all map javascript how to map array of promise all promise all map new promise Promise all and map js promise all map js nodejs map promise.all promise all maps how to map a promise all promise all map subscriptions promise all javascript map return in map after promise.all promise all .map handel result of promise.all map promise .all value.map map promise all results map with promise all array map promise.all promise.all with map and callback promise.all array.map example using promise all with map js map promise all alternative js map promise all promise.all with array.map promise.all map array using promise all with map and return javascript promise all map javascript promise.all map map promise.all promise all with map function promise.all on map funtion promise all array map promise all in map map promise.all example map promise.all js promise.map using promise all with array map javascript Promise.all map function promise all and map using promise.all with map function promise.all() map mapping arrays of promise.all() Promise.map(_ promisee all map promise.all async await map should i put promise.all on map promise all, map, each node js promise map await Promise.all(Promise.map) promise.all map async await promise all map function promise.all(map) promise.all array of promises map promise async all javascript pri=omise.all in map using await with promis all promise allasync await promise.all with async await js map promise Js wait all promises promise.all.map example map inside promise.all promise .map promis.all map map and promises javascriupt javascript array map promise all promise all javascript map in promise.all call promise.all in .map map through promise.all how to make map call in promise all array.map and promise.all promise all with map prmoise all for map inside map javaacript .map promise.all promise all await map js promises all map promise.all(mao) promise.all with map nodejs promiseall values map promise.all javascript map map in promise.all javascript promise all map 2 function how to use await promise.all map and promise all promise all map async/await promise all map js map promise all promise.all map promise all map map async await promise all map and promise all example using map with promise all using map with promise akk Promise.all.then in map
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source