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

116
Visualizações
Why is a the reference of wrapper function still available in the `.then` part of a promise

This following JavaScript snippet works fine:

// generate next extry in order to upadate the
// country html table
app.get('/next', (req, res, next) => {
  data.nextEntry()
    .then(country => tpl.salesForCountry(country))
    .then(html => res.send(html))
    .catch(e => next(e))
})

However, I am asking myself why?

When the get route is called, the Lambda function executes and my custom function nextEntry (it's async) generates a new json object which is then converted to HTML and finally sent back to the requester by calling send of the response object (res).

But why is the reference of res still available and not undefined? Because the Lambda function execution (provided to the get route) has finished long before the HTML has been generated by the then branches. Could somebody kindly point me to the right direction - THX

about 4 years ago · Juan Pablo Isaza
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