@@ -61,6 +61,35 @@ Worker threads inherit non-process-specific options by default. Refer to
6161[ ` Worker constructor options ` ] [ ] to know how to customize worker thread options,
6262specifically ` argv ` and ` execArgv ` options.
6363
64+ ## ` worker.environmentData `
65+ <!-- YAML
66+ added: REPLACEME
67+ -->
68+
69+ > Stability: 1 - Experimental
70+
71+ Within a worker thread, ` worker.environmentData ` is a {Map} containing a clone
72+ of data passed to the spawning thread's ` worker.setEnvironmentData() ` function.
73+ The ` worker.environmentData ` is similar to ` worker.workerData ` except that
74+ every new ` Worker ` receives it's own copy of ` worker.environmentData `
75+ automatically.
76+
77+ ``` js
78+ const {
79+ Worker ,
80+ isMainThread ,
81+ setEnvironmentData ,
82+ environmentData
83+ } = require (' worker_threads' );
84+
85+ if (isMainThread) {
86+ setEnvironmentData (' Hello' , ' World!' );
87+ const worker = new Worker (__filename );
88+ } else {
89+ console .log (environmentData .get (' Hello' )); // Prints 'World!'.
90+ }
91+ ```
92+
6493## ` worker.isMainThread `
6594<!-- YAML
6695added: v10.5.0
@@ -176,32 +205,6 @@ if (isMainThread) {
176205}
177206```
178207
179- ## ` worker.platformData `
180- <!-- YAML
181- added: REPLACEME
182- -->
183-
184- An arbitrary JavaScript value that contains a clone of the data passed
185- to the spawning threads ` worker.setPlatformData() ` function. The
186- ` worker.platformData ` is similar to ` worker.workerData ` except that
187- every new ` Worker ` receives it's own copy of ` platformData ` automatically.
188-
189- ``` js
190- const {
191- Worker ,
192- isMainThread ,
193- setPlatformData ,
194- platformData
195- } = require (' worker_threads' );
196-
197- if (isMainThread) {
198- setPlatformData (' Hello World!' );
199- const worker = new Worker (__filename );
200- } else {
201- console .log (platformData); // Prints 'Hello, world!'.
202- }
203- ```
204-
205208## ` worker.receiveMessageOnPort(port) `
206209<!-- YAML
207210added: v12.3.0
@@ -268,19 +271,25 @@ new Worker('process.env.SET_IN_WORKER = "foo"', { eval: true, env: SHARE_ENV })
268271 });
269272```
270273
271- ## ` worker.setPlatformData( value) `
274+ ## ` worker.setEnvironmentData(key[, value] ) `
272275<!-- YAML
273276added: REPLACEME
274277-->
275278
279+ > Stability: 1 - Experimental
280+
281+ * ` key ` {any} Any arbitrary, cloneable JavaScript value that can be used as a
282+ {Map} key.
276283* ` value ` {any} Any arbitrary, cloneable JavaScript value that will be cloned
277- and passed automatically to all new ` Worker ` instances.
284+ and passed automatically to all new ` Worker ` instances. If ` value ` is passed
285+ as ` undefined ` , any previously set value for the ` key ` will be deleted.
278286
279- The ` worker.setPlatformData() ` API sets the value of the ` worker.platformData `
280- in all new ` Worker ` instances spawned from the current context.
287+ The ` worker.setEnvironmentData() ` API sets the content of the
288+ ` worker.environmentData ` in all new ` Worker ` instances spawned from the current
289+ context.
281290
282- Calling ` worker.setPlatformData () ` will have no impact on the value of
283- ` worker.platformData ` on existing threads.
291+ Calling ` worker.setEnvironmentData () ` will have no impact on the value of
292+ ` worker.environmentData ` on existing threads.
284293
285294## ` worker.threadId `
286295<!-- YAML
0 commit comments