doc: clarify Worker exit/message event ordering

Motivated by the fact that getting this wrong has led to flaky
tests in our test suite.

Refs: https://github.com/nodejs/node/pull/31637

PR-URL: https://github.com/nodejs/node/pull/31642
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
pull/31689/head
Anna Henningsen 2020-02-05 13:09:11 +01:00
parent aee3e2bc4c
commit 7df429808c
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
1 changed files with 5 additions and 0 deletions

View File

@ -584,6 +584,8 @@ exited by calling [`process.exit()`][], the `exitCode` parameter will be the
passed exit code. If the worker was terminated, the `exitCode` parameter will
be `1`.
This is the final event emitted by any `Worker` instance.
### Event: `'message'`
<!-- YAML
added: v10.5.0
@ -595,6 +597,9 @@ The `'message'` event is emitted when the worker thread has invoked
[`require('worker_threads').parentPort.postMessage()`][].
See the [`port.on('message')`][] event for more details.
All messages sent from the worker thread will be emitted before the
[`'exit'` event][] is emitted on the `Worker` object.
### Event: `'online'`
<!-- YAML
added: v10.5.0