Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda