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

246
Vistas
How do generator callback functions work for javascript express routing

I'm trying to understand how the following javascript code summary works

routes = router(); //express router
router.get('/home', callback);

const callback = function *(req, res, next) {
  const a = yield getFromDB(1) //Asynchronous
  const b = yield getFromDB(2) //Asynchronous
  return {
    status: 200,
    body: a + b
  };
};

When the /home url is called via a user, the app returns status 200 and a body of a + b. This implies that the callback generator function gets run all the way through. Does anyone know the specifics of what exactly happens? Is next() getting called on the generator until completion? Is the code blocked for the asynronous getFromDB()? Thanks an advance for anyones help!

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