examples: comment the usage of process.nextTick

closes #2903
closes #2908
This commit is contained in:
Muhammad Saqib 2016-02-25 07:46:14 +05:00 committed by Douglas Christopher Wilson
parent 4bcbf67482
commit dd2b897774
2 changed files with 6 additions and 0 deletions

View File

@ -31,6 +31,9 @@ app.get('/', function(req, res){
app.get('/next', function(req, res, next){
// We can also pass exceptions to next()
// The reason for process.nextTick() is to show that
// next() can be called inside an async operation,
// in real life it can be a DB read or HTTP request.
process.nextTick(function(){
next(new Error('oh no!'));
});

View File

@ -9,6 +9,9 @@ function User(name, age, species) {
}
User.all = function(fn){
// process.nextTick makes sure this function API
// behaves in an asynchronous manner, like if it
// was a real DB query to read all users.
process.nextTick(function(){
fn(null, users);
});