Skip to content

Commit

Permalink
test: process.nextTick for before exit
Browse files Browse the repository at this point in the history
PR-URL: #37012
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
ttzztztz authored and targos committed May 1, 2021
1 parent b808013 commit 456fd75
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/parallel/test-process-beforeexit.js
Expand Up @@ -49,12 +49,24 @@ function tryListen() {
// Test that a function invoked from the beforeExit handler can use a timer
// to keep the event loop open, which can use another timer to keep the event
// loop open, etc.
//
// After N times, call function `tryNextTick` to test behaviors of the
// `process.nextTick`.
function tryRepeatedTimer() {
const N = 5;
let n = 0;
const repeatedTimer = common.mustCall(function() {
if (++n < N)
setTimeout(repeatedTimer, 1);
else // n == N
process.once('beforeExit', common.mustCall(tryNextTick));
}, N);
setTimeout(repeatedTimer, 1);
}

// Test if the callback of `process.nextTick` can be invoked.
function tryNextTick() {
process.nextTick(common.mustCall(function() {
process.once('beforeExit', common.mustNotCall());
}));
}

0 comments on commit 456fd75

Please sign in to comment.