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

85
Visualizações
Return value instead of promise without await

As parent function does not support async. I need to make call without await and get return value. As suggested on most of the posts, applied promise with then and returning value. But it prints as "promise" instead of return "value".

Can you please share, how to achieve return value instead of promise.

code sandbox: https://codesandbox.io/s/await-without-async-and-return-value-qbs7t?file=/src/index.js


await isEnable(data) {
  try {
    ...
    return true;
  }
  catch (e) {
    console.error(e);
  }
}
}

const getEnableStatus=(data) =>{
  return isEnable(data).then((result) =>
    {console.log(result); return result;});  //this prints correctly but, need this in return result.
}

console.log(getEnableStatus(data)); //it always print 'promise'. how to get value here instead of promise.
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Pass in a callback to the getEnableStatus function, and then call it with the returned data.

// Mock function that resolves after
// two seconds
function isEnable() {
  return new Promise((res, rej) => {
    setTimeout(() => res('Hallo!'), 2000);
  });
}

// Accept a callback, and call it with the data
function getEnableStatus(data, callback) {
  isEnable(data).then(callback);
}

// The callback logs the data
getEnableStatus('data', function (data) {
  console.log(data);
});

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