Skip to content

Commit

Permalink
doc: clarify synchronous blocking of MessagePort
Browse files Browse the repository at this point in the history
Fixes: nodejs#25630
Signed-off-by: James M Snell <jasnell@gmail.com>
  • Loading branch information
jasnell committed May 12, 2021
1 parent 184e0f7 commit a2e26c4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions doc/api/worker_threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,29 @@ The `ArrayBuffer`s for `Buffer` instances created using
transferred but doing so renders all other existing views of
those `ArrayBuffer`s unusable.

#### Synchronous blocking of message handling

The `postMessage()` method will defer the actual transmission and
handling of the message until after the current synchronous execution
context completes and the Node.js event loop as allowed to continue
turning.

In the following example, for instance, the `onmessage` handler for
`mc.port1` will not be invoked until after the `for` loop completes
and the Node.js event loop is not blocked.

```js
const mc = new MessageChannel();

mc.port1.onmessage = console.log;

mc.port2.postMessage(1);

for (let n = 0; n < 1e9; n++) {
console.log(n);
}
```

#### Considerations when cloning objects with prototypes, classes, and accessors

Because object cloning uses the [HTML structured clone algorithm][],
Expand Down

0 comments on commit a2e26c4

Please sign in to comment.