• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3require('../common');
4const assert = require('assert');
5const {
6  executionAsyncResource,
7  executionAsyncId,
8  createHook,
9} = require('async_hooks');
10const http = require('http');
11
12const hooked = {};
13createHook({
14  init(asyncId, type, triggerAsyncId, resource) {
15    hooked[asyncId] = resource;
16  }
17}).enable();
18
19const server = http.createServer((req, res) => {
20  res.end('ok');
21});
22
23server.listen(0, () => {
24  assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
25
26  http.get({ port: server.address().port }, () => {
27    assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
28    server.close();
29  });
30});
31