• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const async_hooks = require('async_hooks');
5
6if (!common.isMainThread)
7  common.skip('Worker bootstrapping works differently -> different async IDs');
8
9const initCalls = [];
10const resolveCalls = [];
11
12async_hooks.createHook({
13  init: common.mustCall((id, type, triggerId, resource) => {
14    assert.strictEqual(type, 'PROMISE');
15    initCalls.push({ id, triggerId, resource });
16  }, 2),
17  promiseResolve: common.mustCall((id) => {
18    assert.strictEqual(initCalls[resolveCalls.length].id, id);
19    resolveCalls.push(id);
20  }, 2)
21}).enable();
22
23const a = Promise.resolve(42);
24a.then(common.mustCall());
25
26assert.strictEqual(initCalls[0].triggerId, 1);
27assert.strictEqual(initCalls[1].triggerId, initCalls[0].id);
28