зеркало из https://github.com/electron/electron.git
docs: add utility process info to tutorial docs (#36074)
This commit is contained in:
Родитель
02ad8fcd5f
Коммит
260678bd0c
|
@ -214,8 +214,25 @@ This feature is incredibly useful for two main purposes:
|
|||
URL, you can add custom properties onto the renderer's `window` global that can
|
||||
be used for desktop-only logic on the web client's side.
|
||||
|
||||
## The utility process
|
||||
|
||||
Each Electron app can spawn multiple child processes from the main process using
|
||||
the [UtilityProcess][] API. The utility process runs in a Node.js environment,
|
||||
meaning it has the ability to `require` modules and use all of Node.js APIs.
|
||||
The utility process can be used to host for example: untrusted services,
|
||||
CPU intensive tasks or crash prone components which would have previously
|
||||
been hosted in the main process or process spawned with Node.js [`child_process.fork`][] API.
|
||||
The primary difference between the utility process and process spawned by Node.js
|
||||
child_process module is that the utility process can establish a communication
|
||||
channel with a renderer process using [`MessagePort`][]s. An Electron app can
|
||||
always prefer the [UtilityProcess][] API over Node.js [`child_process.fork`][] API when
|
||||
there is need to fork a child process from the main process.
|
||||
|
||||
[window-mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Window
|
||||
[`MessagePort`]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort
|
||||
[`child_process.fork`]: https://nodejs.org/dist/latest-v16.x/docs/api/child_process.html#child_processforkmodulepath-args-options
|
||||
[context-isolation]: ./context-isolation.md
|
||||
[context-bridge]: ../api/context-bridge.md
|
||||
[ipcrenderer]: ../api/ipc-renderer.md
|
||||
[UtilityProcess]: ../api/utility-process.md
|
||||
[tutorial]: ./tutorial-1-prerequisites.md
|
||||
|
|
Загрузка…
Ссылка в новой задаче