new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Electron · API · all subjects

messagechannelmain/overview

3 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

MessageChannelMain class overview

MessageChannelMain is the main-process-side equivalent of the DOM MessageChannel object. Its singular function is to create a pair of connected MessagePortMain objects. It is available in the main process.

MessageChannelMain cannot be subclassed

Electron's built-in classes cannot be subclassed in user code. MessageChannelMain is one of these classes and cannot be extended.

MessageChannelMain channel messaging example

Example of using MessageChannelMain for channel messaging: In the main process, create a new MessageChannelMain instance to get port1 and port2, send port2 to a renderer process using webContents.postMessage, and then use port1.postMessage to send messages. In the renderer process, listen for the 'port' event with ipcRenderer.on, access the received port via e.ports[0], set an onmessage handler to receive messages, and access the message data via messageEvent.data. // Main process const { BrowserWindow, MessageChannelMain } = require('electron') const w = new BrowserWindow() const { port1, port2 } = new MessageChannelMain() w.webContents.postMessage('port', null, [port2]) port1.postMessage({ some: 'message' }) // Renderer process const { ipcRenderer } = require('electron') ipcRenderer.on('port', (e) => { // e.ports is a list of ports sent along with this message e.ports[0].onmessage = (messageEvent) => { console.log(messageEvent.data) } })

Give your agent this brain