Wednesday, 3 June 2020

Stuck on understanding asyncHandler

Guys I am learning Nodejs. I used to work on PHP/Laravel before.Problem isI am currently stuck on understanding how asyncHandler really works. I understand that asyncHandler is a wrapper method for controller methods. So that We don't have to write try/catch on every method that we call on controller or services/repo(that is a good dry). I also understand that async/await returns promises so *return Promise.resolve(fn(req, res, next)).catch(next);* is acting as a try/catch on below snippet. but What I don't understand is how come *return function(req,res,next)* has access to those variables??Can somebody explain this to me ?? I feel that I am about to understand what is going on but I am not getting that tick on my brain.https://preview.redd.it/by4kzydfmp251.png?width=482&format=png&auto=webp&s=4b52d7baf3aa484521da3736d9f2bb93dfe9b155

Submitted June 03, 2020 at 04:01PM by Sagarmatha007

No comments:

Post a Comment