Skip to content

Commit d1549bf

Browse files
danbevitaloacasas
authored andcommitted
lib: add constant kMaxCallbacksUntilQueueIsShortened
Currently the maximum number of tick is duplicated in two places. This commit introduces a constant that both can use. PR-URL: #11199 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
1 parent 48f6660 commit d1549bf

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/internal/process/next_tick.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
'use strict';
22

3+
// This value is used to prevent the nextTickQueue from becoming too
4+
// large and cause the process to run out of memory. When this value
5+
// is reached the nextTimeQueue array will be shortend (see tickDone
6+
// for details).
7+
const kMaxCallbacksUntilQueueIsShortened = 1e4;
8+
39
exports.setup = setupNextTick;
410

511
function setupNextTick() {
@@ -96,7 +102,7 @@ function setupNextTick() {
96102
// callback invocation with small numbers of arguments to avoid the
97103
// performance hit associated with using `fn.apply()`
98104
_combinedTickCallback(args, callback);
99-
if (1e4 < tickInfo[kIndex])
105+
if (kMaxCallbacksUntilQueueIsShortened < tickInfo[kIndex])
100106
tickDone();
101107
}
102108
tickDone();
@@ -120,7 +126,7 @@ function setupNextTick() {
120126
// callback invocation with small numbers of arguments to avoid the
121127
// performance hit associated with using `fn.apply()`
122128
_combinedTickCallback(args, callback);
123-
if (1e4 < tickInfo[kIndex])
129+
if (kMaxCallbacksUntilQueueIsShortened < tickInfo[kIndex])
124130
tickDone();
125131
if (domain)
126132
domain.exit();

0 commit comments

Comments
 (0)