• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const { AsyncResource, executionAsyncId } = require('async_hooks');
6
7const fn = common.mustCall(AsyncResource.bind(() => {
8  return executionAsyncId();
9}));
10
11setImmediate(() => {
12  const asyncId = executionAsyncId();
13  assert.notStrictEqual(asyncId, fn());
14});
15
16const asyncResource = new AsyncResource('test');
17
18[1, false, '', {}, []].forEach((i) => {
19  assert.throws(() => asyncResource.bind(i), {
20    code: 'ERR_INVALID_ARG_TYPE'
21  });
22});
23
24const fn2 = asyncResource.bind((a, b) => {
25  return executionAsyncId();
26});
27
28assert.strictEqual(fn2.asyncResource, asyncResource);
29assert.strictEqual(fn2.length, 2);
30
31setImmediate(() => {
32  const asyncId = executionAsyncId();
33  assert.strictEqual(asyncResource.asyncId(), fn2());
34  assert.notStrictEqual(asyncId, fn2());
35});
36