Zum Hauptteil springen

parentPort

Interface for communication with parent process.

Process: Utility

parentPort ist ein EventEmitter. This object is not exported from the 'electron' module. It is only available as a property of the process object in the Electron API.

// Main process
const child = utilityProcess.fork(path.join(__dirname, 'test.js'))
child.postMessage({ message: 'hello' })
child.on('message', (data) => {
console.log(data) // hello world!
})

// Child process
process.parentPort.on('message', (e) => {
process.parentPort.postMessage(`${e.data} world!`)
})

Ereignisse

Das parentPort - Object gibt die folgenden Ereignisse aus:

Event: 'message'

Kehrt zurück:

  • messageEvent Object
    • data any
    • ports MessagePortMain[]

Emitted when the process receives a message. Messages received on this port will be queued up until a handler is registered for this event.

Methoden

parentPort.postMessage(message)

  • message any

Sends a message from the process to its parent.