2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2013-10-25 14:05:39 -07:00
|
|
|
var assert = require('assert');
|
|
|
|
var net = require('net');
|
2014-12-17 20:30:04 +07:00
|
|
|
var common = require('../common');
|
2013-10-25 14:05:39 -07:00
|
|
|
var revivals = 0;
|
|
|
|
var deaths = 0;
|
|
|
|
|
2016-01-19 03:23:07 +01:00
|
|
|
process.on('beforeExit', function() { deaths++; });
|
2013-10-25 14:05:39 -07:00
|
|
|
|
|
|
|
process.once('beforeExit', tryImmediate);
|
|
|
|
|
|
|
|
function tryImmediate() {
|
|
|
|
console.log('set immediate');
|
|
|
|
setImmediate(function() {
|
|
|
|
revivals++;
|
|
|
|
process.once('beforeExit', tryTimer);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function tryTimer() {
|
|
|
|
console.log('set a timeout');
|
2015-05-19 13:00:06 +02:00
|
|
|
setTimeout(function() {
|
2013-10-25 14:05:39 -07:00
|
|
|
console.log('timeout cb, do another once beforeExit');
|
|
|
|
revivals++;
|
|
|
|
process.once('beforeExit', tryListen);
|
|
|
|
}, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
function tryListen() {
|
|
|
|
console.log('create a server');
|
|
|
|
net.createServer()
|
2014-12-17 20:30:04 +07:00
|
|
|
.listen(common.PORT)
|
2013-10-25 14:05:39 -07:00
|
|
|
.on('listening', function() {
|
|
|
|
revivals++;
|
|
|
|
this.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
assert.equal(4, deaths);
|
|
|
|
assert.equal(3, revivals);
|
|
|
|
});
|