![]() |
VOOZH | about |
The MessageChannel.postMessage() method is an inbuilt application programming interface of class Worker within worker_threads module which is used to send the message from one port to another.
Syntax:
const MessageChannel.postMessage(value[, transferList])
Parameters: This method takes the value as a parameter which can contain any kind of object.
Return Value: This method sends the message from one port to another.
Example 1: Filename: index.js
Output:
received data in port1 :
{ message: { hello: 'world2' } }
received data in port2 :
{ message: { hello: 'world1' } }
Example 2: Filename: index.js
Output:
GFG closed!
Run the index.js file using the following command:
node index.js