Skip to content

Commit 9b0249a

Browse files
addaleaxcodebytere
authored andcommitted
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: #31637 PR-URL: #31642 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 190f0fd commit 9b0249a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

doc/api/worker_threads.md

+5
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ exited by calling [`process.exit()`][], the `exitCode` parameter will be the
582582
passed exit code. If the worker was terminated, the `exitCode` parameter will
583583
be `1`.
584584

585+
This is the final event emitted by any `Worker` instance.
586+
585587
### Event: `'message'`
586588
<!-- YAML
587589
added: v10.5.0
@@ -593,6 +595,9 @@ The `'message'` event is emitted when the worker thread has invoked
593595
[`require('worker_threads').parentPort.postMessage()`][].
594596
See the [`port.on('message')`][] event for more details.
595597

598+
All messages sent from the worker thread will be emitted before the
599+
[`'exit'` event][] is emitted on the `Worker` object.
600+
596601
### Event: `'online'`
597602
<!-- YAML
598603
added: v10.5.0

0 commit comments

Comments
 (0)