0

This works fine :

const querySources = async() => {

  return new Promise((resolve, reject) => {

    if (apiLinks !== undefined){
      resolve();
    }else{
      fetchLinks()
      .then(links => {
        resolve(links)
      })
      .catch(err => {
        reject(err);
      })
    }

  });

}

But this doesn't work - and I don't understand why.

const querySources = async() => {

  return new Promise((resolve, reject) => {

    if (apiLinks !== undefined){
      resolve();
    }else{
      return fetchLinks()
    }

  });

}

Can someone explain why ?

Thanks !

gordie
  • 1,637
  • 3
  • 21
  • 41
  • 1
    `return fetchLinks()` will not resolve the promise. – VLAZ May 21 '21 at 15:00
  • Why are you using `new Promise` with something that already returns a promise? – jonrsharpe May 21 '21 at 15:01
  • 1
    The whole promise is not needed in your code at all: [What is the explicit promise construction antipattern and how do I avoid it?](https://stackoverflow.com/q/23803743) You already have an async function, which does implicitly return a promise anyway. – VLAZ May 21 '21 at 15:02

0 Answers0