• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3require('../common');
4const {
5  Worker,
6  getEnvironmentData,
7  setEnvironmentData,
8  threadId,
9} = require('worker_threads');
10
11const {
12  deepStrictEqual,
13  strictEqual,
14} = require('assert');
15
16if (!process.env.HAS_STARTED_WORKER) {
17  process.env.HAS_STARTED_WORKER = 1;
18  setEnvironmentData('foo', 'bar');
19  setEnvironmentData('hello', { value: 'world' });
20  setEnvironmentData(1, 2);
21  strictEqual(getEnvironmentData(1), 2);
22  setEnvironmentData(1); // Delete it, key won't show up in the worker.
23  new Worker(__filename);
24  setEnvironmentData('hello');  // Delete it. Has no impact on the worker.
25} else {
26  strictEqual(getEnvironmentData('foo'), 'bar');
27  deepStrictEqual(getEnvironmentData('hello'), { value: 'world' });
28  strictEqual(getEnvironmentData(1), undefined);
29
30  // Recurse to make sure the environment data is inherited
31  if (threadId <= 2)
32    new Worker(__filename);
33}
34