mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
d2c96af152
Combine and rename tests for the `beforeExit` event on `process`. The naming now more closely follows the de facto conventions of the project. The two tests were very similar and do not seem to benefit from being separate. PR-URL: https://github.com/nodejs/node/pull/10581 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
40 lines
996 B
JavaScript
40 lines
996 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const net = require('net');
|
|
|
|
process.once('beforeExit', common.mustCall(tryImmediate));
|
|
|
|
function tryImmediate() {
|
|
setImmediate(common.mustCall(() => {
|
|
process.once('beforeExit', common.mustCall(tryTimer));
|
|
}));
|
|
}
|
|
|
|
function tryTimer() {
|
|
setTimeout(common.mustCall(() => {
|
|
process.once('beforeExit', common.mustCall(tryListen));
|
|
}), 1);
|
|
}
|
|
|
|
function tryListen() {
|
|
net.createServer()
|
|
.listen(0)
|
|
.on('listening', common.mustCall(function() {
|
|
this.close();
|
|
process.once('beforeExit', common.mustCall(tryRepeatedTimer));
|
|
}));
|
|
}
|
|
|
|
// 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.
|
|
function tryRepeatedTimer() {
|
|
const N = 5;
|
|
let n = 0;
|
|
const repeatedTimer = common.mustCall(function() {
|
|
if (++n < N)
|
|
setTimeout(repeatedTimer, 1);
|
|
}, N);
|
|
setTimeout(repeatedTimer, 1);
|
|
}
|