Skip to content

Commit af9ba4e

Browse files
authored
remove the outdated Deduplication section
Deduplication section appears to be describing how things worked prior to nodejs/node#22842, so is no longer correct. The output in 11.12 is ``` setImmediate 1 process.nextTick a process.nextTick b setImmediate 2 process.nextTick a process.nextTick b ```
1 parent e90e6d5 commit af9ba4e

File tree

1 file changed

+0
-50
lines changed

1 file changed

+0
-50
lines changed

locale/en/docs/guides/event-loop-timers-and-nexttick.md

-50
Original file line numberDiff line numberDiff line change
@@ -398,56 +398,6 @@ To get around this, the `'listening'` event is queued in a `nextTick()`
398398
to allow the script to run to completion. This allows the user to set
399399
any event handlers they want.
400400

401-
### Deduplication
402-
403-
For the `timers` and `check` phases, there is a single transition
404-
between C to JavaScript for multiple immediates and timers. This deduplication
405-
is a form of optimization, which may produce some unexpected side effects.
406-
Take this code snippet as an example:
407-
408-
```js
409-
// dedup.js
410-
const foo = [1, 2];
411-
const bar = ['a', 'b'];
412-
413-
foo.forEach(num => {
414-
setImmediate(() => {
415-
console.log('setImmediate', num);
416-
bar.forEach(char => {
417-
process.nextTick(() => {
418-
console.log('process.nextTick', char);
419-
});
420-
});
421-
});
422-
});
423-
```
424-
```bash
425-
$ node dedup.js
426-
setImmediate 1
427-
setImmediate 2
428-
process.nextTick a
429-
process.nextTick b
430-
process.nextTick a
431-
process.nextTick b
432-
```
433-
434-
The main thread adds two `setImmediate()` events, which when processed
435-
will add two `process.nextTick()` events. When the event loop reaches
436-
the `check` phase, it sees that there are currently two events created by
437-
`setImmediate()`. The first event is grabbed and processed, which prints
438-
and adds two events to the `nextTickQueue`.
439-
440-
Because of deduplication, the event loop does not transition back to the
441-
C/C++ layer to check if there are items in the `nextTickQueue` immediately. It
442-
instead continues to process any remaining `setImmediate()` events, of which
443-
one currently remains. After processing this event, two more events are
444-
added to the `nextTickQueue` for a total of four events.
445-
446-
At this point, all previously added `setImmediate()` events have been processed.
447-
The `nextTickQueue` is now checked, and events are processed in FIFO order. When
448-
this `nextTickQueue` is emptied, the event loop considers all operations to have
449-
been completed for the current phase and transitions to the next phase.
450-
451401
## `process.nextTick()` vs `setImmediate()`
452402

453403
We have two calls that are similar as far as users are concerned, but

0 commit comments

Comments
 (0)