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!