mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 00:19:48 +01:00
examples: comment the usage of process.nextTick
closes #2903 closes #2908
This commit is contained in:
parent
4bcbf67482
commit
dd2b897774
|
|
@ -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!'));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user