mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
787143bf3e
This was an oversight in 9fdb6e6aaf
.
Fixing this is necessary to make `executionAsyncResource()` work
as expected.
Refs: https://github.com/nodejs/node/pull/30959
Fixes: https://github.com/nodejs/node/issues/32060
PR-URL: https://github.com/nodejs/node/pull/32063
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
38 lines
957 B
JavaScript
38 lines
957 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const {
|
|
executionAsyncResource,
|
|
executionAsyncId,
|
|
createHook,
|
|
} = require('async_hooks');
|
|
const http = require('http');
|
|
|
|
const hooked = {};
|
|
createHook({
|
|
init(asyncId, type, triggerAsyncId, resource) {
|
|
hooked[asyncId] = resource;
|
|
}
|
|
}).enable();
|
|
|
|
const server = http.createServer((req, res) => {
|
|
res.write('hello');
|
|
setTimeout(() => {
|
|
res.end(' world!');
|
|
}, 1000);
|
|
});
|
|
|
|
server.listen(0, () => {
|
|
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
|
|
http.get({ port: server.address().port }, (res) => {
|
|
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
|
|
res.on('data', () => {
|
|
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
|
|
});
|
|
res.on('end', () => {
|
|
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
|
|
server.close();
|
|
});
|
|
});
|
|
});
|