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

309
Visualizações
How to use async functions within functions?

So lets say you have this sync function you call a and another async function b that you want to put within a. And so you would have something like this:

async function b(){
      //some code here
}
function a(){
    

}

And now lets say we add some code into a and call b:

async function b(){
      //some code here
}
function a(){
      b()
      //other code here
}

Now lets say you want to run the code within a only if b has returned its promise. Well if you have direct access to b then its all fine, just make it a sync function. That would work but what if you didn't have access to b. Here comes the problem. If you specifically want to run it after b then you could use something like .then():

async function b(){
     //some code here
}
function a(){
     b().then(<results for example>=>{
     //other code
     })
}

But what if a was an async function, how would that work? Could i use await or anything of that sort?

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

0

You have to make a function async and await for b function, then b function will return data, otherwise it will return promise.

async function b(){
    //some code here
}
async function a(){
    const data = await b();
    // Do something with 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