Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: update MessagePort documentation for EventTarget inheritance #35839

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions doc/api/worker_threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ inherit from its global `Object` class. Objects passed to the
and inherit from its global `Object` class.

However, the created `MessagePort` will no longer inherit from
[`EventEmitter`][], and only [`port.onmessage()`][] can be used to receive
[`EventTarget`][], and only [`port.onmessage()`][] can be used to receive
events using it.

## `worker.parentPort`
Expand Down Expand Up @@ -297,17 +297,22 @@ port2.postMessage({ foo: 'bar' });
## Class: `MessagePort`
<!-- YAML
added: v10.5.0
changes:
- version:
- v14.7.0
pr-url: https://github.com/nodejs/node/pull/34057
description: This class now inherits from `EventTarget` rather than
from `EventEmitter`.
-->

* Extends: {EventEmitter}
* Extends: {EventTarget}

Instances of the `worker.MessagePort` class represent one end of an
asynchronous, two-way communications channel. It can be used to transfer
structured data, memory regions and other `MessagePort`s between different
[`Worker`][]s.

With the exception of `MessagePort`s being [`EventEmitter`][]s rather
than [`EventTarget`][]s, this implementation matches [browser `MessagePort`][]s.
This implementation matches [browser `MessagePort`][]s.

### Event: `'close'`
<!-- YAML
Expand Down Expand Up @@ -986,7 +991,6 @@ active handle in the event system. If the worker is already `unref()`ed calling
[`Buffer`]: buffer.md
[`ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST`]: errors.md#errors_err_missing_message_port_in_transfer_list
[`ERR_WORKER_NOT_RUNNING`]: errors.md#ERR_WORKER_NOT_RUNNING
[`EventEmitter`]: events.md
[`EventTarget`]: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
[`FileHandle`]: fs.md#fs_class_filehandle
[`KeyObject`]: crypto.md#crypto_class_keyobject
Expand Down