Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!