What is a callback referring to in this context of the code?async.parallel({ book_count: function (callback) { BookModel.countDocuments({}, callback); }, author_count: function (callback) { AuthorModel.countDocuments({}, callback); }, genre_count: function (callback) { GenreModel.countDocuments({}, callback); } }, function(err, results) { res.render('index', { title: 'Library Home', error: err, data: results }); }; }; My understanding:after BookModel gets the info from the database, it will call the function(err, results) in the end, where the value is stored in the results.then,it will move on to the AuthorModel gets the info from the database, it will call the function(err, results) in the end, where the value is stored in the results.thenit will move on to the GenreModel, gets the info from the database, it will call the function(err, results) in the end, where the value is stored in the results.But my understanding doesn't make sense, because if for example BookModel were to call the function(err, results) and store the info to results. how would it know to get back to AuthorModel and then GenreModel?I don't know, I'm banging my head here, can anyone help me understand this conceptually?what is 'callback' ? which function is it referring to?and if it's referring to the function(err, results), how does it know to chain the other models result back into the function(err, results)??Thank you kindly.
Submitted June 03, 2020 at 11:52PM by Mmsn1234
No comments:
Post a Comment