diff --git a/doc/api/worker_threads.md b/doc/api/worker_threads.md index 7942788df58e5d..5af287916d0456 100644 --- a/doc/api/worker_threads.md +++ b/doc/api/worker_threads.md @@ -176,6 +176,32 @@ if (isMainThread) { } ``` +## `worker.platformData` + + +An arbitrary JavaScript value that contains a clone of the data passed +to the spawning threads `worker.setPlatformData()` function. The +`worker.platformData` is similar to `worker.workerData` except that +every new `Worker` receives it's own copy of `platformData` automatically. + +```js +const { + Worker, + isMainThread, + setPlatformData, + platformData +} = require('worker_threads'); + +if (isMainThread) { + setPlatformData('Hello World!'); + const worker = new Worker(__filename); +} else { + console.log(platformData); // Prints 'Hello, world!'. +} +``` + ## `worker.receiveMessageOnPort(port)` + +* `value` {any} Any arbitrary, cloneable JavaScript value that will be cloned + and passed automatically to all new `Worker` instances. + +The `worker.setPlatformData()` API sets the value of the `worker.platformData` +in all new `Worker` instances spawned from the current context. + +Calling `worker.setPlatformData()` will have no impact on the value of +`worker.platformData` on existing threads. + ## `worker.threadId`