Skip to content

Commit dd2b897

Browse files
Muhammad Saqibdougwilson
authored andcommitted
examples: comment the usage of process.nextTick
closes #2903 closes #2908
1 parent 4bcbf67 commit dd2b897

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

examples/error/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ app.get('/', function(req, res){
3131

3232
app.get('/next', function(req, res, next){
3333
// We can also pass exceptions to next()
34+
// The reason for process.nextTick() is to show that
35+
// next() can be called inside an async operation,
36+
// in real life it can be a DB read or HTTP request.
3437
process.nextTick(function(){
3538
next(new Error('oh no!'));
3639
});

examples/view-locals/user.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ function User(name, age, species) {
99
}
1010

1111
User.all = function(fn){
12+
// process.nextTick makes sure this function API
13+
// behaves in an asynchronous manner, like if it
14+
// was a real DB query to read all users.
1215
process.nextTick(function(){
1316
fn(null, users);
1417
});

0 commit comments

Comments
 (0)