Skip to content

Commit b510cdc

Browse files
thefourtheyetargos
authored andcommitted
doc: fix worker example to receive message
`require('worker_threads')` is not an instance of `EventEmitter`. So `on` method would not be in it. The correct way to receive the message would be to attach a listener to the `message` event on the `parentPort`. PR-URL: #21486 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 580071d commit b510cdc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

doc/api/worker_threads.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ added: v10.5.0
377377
* `transferList` {Object[]}
378378

379379
Send a message to the worker that will be received via
380-
[`require('worker_threads').on('message')`][].
380+
[`require('worker_threads').parentPort.on('message')`][].
381381
See [`port.postMessage()`][] for more details.
382382

383383
### worker.ref()
@@ -480,7 +480,7 @@ active handle in the event system. If the worker is already `unref()`ed calling
480480
[`process.stdout`]: process.html#process_process_stdout
481481
[`process.title`]: process.html#process_process_title
482482
[`require('worker_threads').workerData`]: #worker_threads_worker_workerdata
483-
[`require('worker_threads').on('message')`]: #worker_threads_event_message_1
483+
[`require('worker_threads').parentPort.on('message')`]: #worker_threads_event_message
484484
[`require('worker_threads').postMessage()`]: #worker_threads_worker_postmessage_value_transferlist
485485
[`require('worker_threads').isMainThread`]: #worker_threads_worker_ismainthread
486486
[`require('worker_threads').parentPort`]: #worker_threads_worker_parentport

0 commit comments

Comments
 (0)