Skip to content

Commit 7df4298

Browse files
committed
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 aee3e2b commit 7df4298

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
@@ -584,6 +584,8 @@ exited by calling [`process.exit()`][], the `exitCode` parameter will be the
584584
passed exit code. If the worker was terminated, the `exitCode` parameter will
585585
be `1`.
586586

587+
This is the final event emitted by any `Worker` instance.
588+
587589
### Event: `'message'`
588590
<!-- YAML
589591
added: v10.5.0
@@ -595,6 +597,9 @@ The `'message'` event is emitted when the worker thread has invoked
595597
[`require('worker_threads').parentPort.postMessage()`][].
596598
See the [`port.on('message')`][] event for more details.
597599

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

0 commit comments

Comments
 (0)