Monday 27 May 2019

Event loop related question, I am confused.

I've just studied Node.js event loop and I have a question:​While making API's in express, consider this snippet:​​try { const result = await ColorTrends.findAll(); return res.status(200).json({ success: true, data: result }); } catch (err) { return res.status(500).json({ success: false, errors: err }); } ​I suppose that behind the scenes the event loop being non blocking, it should execute the return res.status(200).json({success:true....}) and would return the response later on. But this does not happen, it waits for the promise to resolve and then returns, why is this so, shouldn't the callback be pushed to event queue?

Submitted May 28, 2019 at 02:45AM by MuhammadHasham

No comments:

Post a Comment