Web APIs
MessageChannel()
Creates a pair of entangled message ports.
Formal Syntax & Structure
javascript syntaxjavascript
new MessageChannel()Return Value
MessageChannel
Creates a pair of entangled message ports.
Working Example
Example Snippetjavascript
(async () => {const {port1,port2}=new MessageChannel();try{const received=new Promise(ok=>port2.onmessage=e=>ok(e.data));port1.postMessage("hello");console.log(await received);}finally{port1.close();port2.close();}})()