You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

39 lines
996 B

'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);
}