Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
Promise not resolving even with status of fulfilled and target data on PromiseResult

I need help on this issue I'm experiencing (I have already searched Stack overflow extensively but could not solve it on my own).

I have the following "dummy" logic to test async/await behaviour:

const data = [1, 2, 3]

async function newData() {
  return data
}

async function getData() {
  const fetchedData = await newData();
  return fetchedData
}

console.log(
  (async () => await getData())()
)

Even though I have awaited for all Promise fulfillings, the following data is returned from the console log:

Console.log return

What am I doing wrong? Why doesn't the Promise return the value but remains pending even though it is 'fulfilled'?

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

All async functions return a promise. That's why newData(), getData() and your async IIFE you have buried in a console.log() ALL return a promise. When you return a value from an async function, that returned value just becomes the resolved value of the promise that the async function returns. An async function NEVER returns the value directly.

So, even this:

(async () => await getData())()

is an async function that returns a promise.

To get the resolved value from an async function, you MUST use .then() or await:

// this must be inside an async function or
// in an environment where top level await is allowed
console.log(await getData());

or:

getData().then(result => {
    console.log(result);
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda