mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 07:53:06 +01:00
cf46746b8a
PR-URL: https://github.com/nodejs/node/pull/45549 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
38 lines
958 B
JavaScript
38 lines
958 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();
|
|
});
|
|
});
|
|
});
|