Skip to main content
MessageChannel - node__worker_threads.d.ts - Node documentation
class MessageChannel

Usage in Deno

```typescript import { MessageChannel } from "node:node__worker_threads.d.ts"; ```
Instances of the `worker.MessageChannel` class represent an asynchronous, two-way communications channel. The `MessageChannel` has no methods of its own. `new MessageChannel()` yields an object with `port1` and `port2` properties, which refer to linked `MessagePort` instances. ```js import { MessageChannel } from 'node:worker_threads'; const { port1, port2 } = new MessageChannel(); port1.on('message', (message) => console.log('received', message)); port2.postMessage({ foo: 'bar' }); // Prints: received { foo: 'bar' } from the `port1.on('message')` listener ```

Properties

variable MessageChannel
`MessageChannel` class is a global reference for `import { MessageChannel } from 'worker_threads'` https://nodejs.org/api/globals.html#messagechannel

Type

globalThis extends { onmessage: any; MessageChannel: infer T; } ? T : _MessageChannel