-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add show-me for
utilityProcess
(#1651)
chore: add show-me for utilityProcess
- Loading branch information
1 parent
7a37cd9
commit 3452e12
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
process.parentPort.on('message', (e) => { | ||
if (e.data === 'Hello from parent!') { | ||
process.parentPort.postMessage('Hello from child!') | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// The "utilityProcess" module allows creating a child process with | ||
// Node.js and Message ports enabled.It provides the equivalent of[`child_process.fork`][] API from Node.js | ||
// but instead uses[Services API][] from Chromium to launch the child process. | ||
// | ||
// For more info, see: | ||
// https://electronjs.org/docs/api/utility-process | ||
|
||
const { app, utilityProcess } = require('electron/main') | ||
const path = require('node:path') | ||
|
||
app.whenReady().then(() => { | ||
const child = utilityProcess.fork(path.join(__dirname, 'child.js')) | ||
|
||
child.on('spawn', () => { | ||
console.log(`Child process spawned with PID: ${child.pid}`) | ||
child.postMessage('Hello from parent!') | ||
}) | ||
|
||
child.on('message', (message) => { | ||
console.log(`Received message from child: ${message}`) | ||
}) | ||
|
||
child.on('exit', (code) => { | ||
console.log(`Child exited with code: ${code}`) | ||
}) | ||
}) |