diff --git a/doc/api/worker_threads.md b/doc/api/worker_threads.md index 840b831c903f6d..95cdae5f9a81af 100644 --- a/doc/api/worker_threads.md +++ b/doc/api/worker_threads.md @@ -4,8 +4,8 @@ > Stability: 1 - Experimental -The `worker_threads` module enables the use of threads with message channels -between them. To access it: +The `worker_threads` module enables the use of threads that execute JS code +in parallel. To access it: ```js const worker = require('worker_threads'); @@ -58,6 +58,18 @@ added: v10.5.0 Is `true` if this code is not running inside of a [`Worker`][] thread. +```js +const { Worker, isMainThread } = require('worker_threads'); + +if (isMainThread) { + // This re-loads the current file inside a Worker instance. + new Worker(__filename); +} else { + console.log('Inside Worker!'); + console.log(isMainThread); // Prints 'false'. +} +``` + ## worker.parentPort