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: https://github.com/nodejs/node/pull/21486
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Sakthipriyan Vairamani (thefourtheye) 2018-06-23 17:10:10 +05:30 committed by Ruben Bridgewater
parent 39902e288e
commit 42be4c3bef
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

@ -377,7 +377,7 @@ added: v10.5.0
* `transferList` {Object[]}
Send a message to the worker that will be received via
[`require('worker_threads').on('message')`][].
[`require('worker_threads').parentPort.on('message')`][].
See [`port.postMessage()`][] for more details.
### worker.ref()
@ -480,7 +480,7 @@ active handle in the event system. If the worker is already `unref()`ed calling
[`process.stdout`]: process.html#process_process_stdout
[`process.title`]: process.html#process_process_title
[`require('worker_threads').workerData`]: #worker_threads_worker_workerdata
[`require('worker_threads').on('message')`]: #worker_threads_event_message_1
[`require('worker_threads').parentPort.on('message')`]: #worker_threads_event_message
[`require('worker_threads').postMessage()`]: #worker_threads_worker_postmessage_value_transferlist
[`require('worker_threads').isMainThread`]: #worker_threads_worker_ismainthread
[`require('worker_threads').parentPort`]: #worker_threads_worker_parentport