File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -454,14 +454,24 @@ This will generate:
454454
455455## process.nextTick(callback)
456456
457- On the next loop around the event loop call this callback.
457+ * ` callback ` {Function}
458+
459+ Once the current event loop turn runs to completion, call the callback
460+ function.
461+
458462This is * not* a simple alias to ` setTimeout(fn, 0) ` , it's much more
459- efficient. It typically runs before any other I/O events fire, but there
460- are some exceptions .
463+ efficient. It runs before any additional I/O events (including
464+ timers) fire in subsequent ticks of the event loop .
461465
466+ console.log('start');
462467 process.nextTick(function() {
463468 console.log('nextTick callback');
464469 });
470+ console.log('scheduled');
471+ // Output:
472+ // start
473+ // scheduled
474+ // nextTick callback
465475
466476This is important in developing APIs where you want to give the user the
467477chance to assign event handlers after an object has been constructed,
@@ -513,6 +523,11 @@ This approach is much better:
513523 fs.stat('file', cb);
514524 }
515525
526+ Note: the nextTick queue is completely drained on each pass of the
527+ event loop ** before** additional I/O is processed. As a result,
528+ recursively setting nextTick callbacks will block any I/O from
529+ happening, just like a ` while(true); ` loop.
530+
516531## process.umask([ mask] )
517532
518533Sets or reads the process's file mode creation mask. Child processes inherit
You can’t perform that action at this time.
0 commit comments