mirror of https://github.com/lukechilds/node.git
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.
40 lines
996 B
40 lines
996 B
10 years ago
|
'use strict';
|
||
8 years ago
|
const common = require('../common');
|
||
|
const net = require('net');
|
||
11 years ago
|
|
||
8 years ago
|
process.once('beforeExit', common.mustCall(tryImmediate));
|
||
11 years ago
|
|
||
|
function tryImmediate() {
|
||
8 years ago
|
setImmediate(common.mustCall(() => {
|
||
|
process.once('beforeExit', common.mustCall(tryTimer));
|
||
|
}));
|
||
11 years ago
|
}
|
||
|
|
||
|
function tryTimer() {
|
||
8 years ago
|
setTimeout(common.mustCall(() => {
|
||
|
process.once('beforeExit', common.mustCall(tryListen));
|
||
|
}), 1);
|
||
11 years ago
|
}
|
||
|
|
||
|
function tryListen() {
|
||
|
net.createServer()
|
||
9 years ago
|
.listen(0)
|
||
8 years ago
|
.on('listening', common.mustCall(function() {
|
||
11 years ago
|
this.close();
|
||
8 years ago
|
process.once('beforeExit', common.mustCall(tryRepeatedTimer));
|
||
8 years ago
|
}));
|
||
11 years ago
|
}
|
||
8 years ago
|
|
||
|
// 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);
|
||
|
}
|