• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const { Worker } = require('worker_threads');
5
6// Like test-async-hooks-worker-promise.js but doing a trivial counter increase
7// after process.exit(). This should not make a difference, but apparently it
8// does. This is *also* different from test-async-hooks-worker-promise-3.js,
9// in that the statement is an ArrayBuffer access rather than a full method,
10// which *also* makes a difference even though it shouldn’t.
11
12const workerData = new Int32Array(new SharedArrayBuffer(4));
13const w = new Worker(`
14const { createHook } = require('async_hooks');
15
16setImmediate(async () => {
17  createHook({ init() {} }).enable();
18  await 0;
19  process.exit();
20  workerData[0]++;
21});
22`, { eval: true, workerData });
23
24w.on('exit', common.mustCall(() => assert.strictEqual(workerData[0], 0)));
25