mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
bb1bd76395
Call a user's callback to notify that the handle has been destroyed. Only pass the id of the AsyncWrap instance since the object no longer exists. The object that's being destructed should never be inspected within the callback or any time afterward. This commit make a breaking change. The init callback will now be passed arguments in the order of provider, id, parent. PR-URL: https://github.com/nodejs/node/pull/3461 Reviewed-By: Fedor Indutny <fedor@indutny.com>
44 lines
956 B
JavaScript
44 lines
956 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const net = require('net');
|
|
const async_wrap = process.binding('async_wrap');
|
|
|
|
let cntr = 0;
|
|
let server;
|
|
let client;
|
|
|
|
function init(type, id, parent) {
|
|
if (parent) {
|
|
cntr++;
|
|
// Cannot assert in init callback or will abort.
|
|
process.nextTick(() => {
|
|
assert.equal(parent, server._handle, 'server doesn\'t match parent');
|
|
assert.equal(this, client._handle, 'client doesn\'t match context');
|
|
});
|
|
}
|
|
}
|
|
|
|
function noop() { }
|
|
|
|
async_wrap.setupHooks(init, noop, noop);
|
|
async_wrap.enable();
|
|
|
|
server = net.createServer(function(c) {
|
|
client = c;
|
|
// Allow init callback to run before closing.
|
|
setImmediate(() => {
|
|
c.end();
|
|
this.close();
|
|
});
|
|
}).listen(common.PORT, function() {
|
|
net.connect(common.PORT, noop);
|
|
});
|
|
|
|
|
|
process.on('exit', function() {
|
|
// init should have only been called once with a parent.
|
|
assert.equal(cntr, 1);
|
|
});
|