电子框架是否允许通过网络工作者进行多线程?

2022-01-10 00:00:00 electron javascript

如果我制作了一个电子应用程序,我很难在谷歌上搜索我将如何进行多线程.会是网络工作者吗?

I am having a hard time googling how I would do multi-threading if I made an electron app. Would it be with web workers?

推荐答案

在渲染进程中你可以创建Web Workers,并且这些将在自己的线程中运行,但是 在这些 Web Workers 中将禁用节点集成 因为 Node 不是线程安全的.因此,如果您想在使用 Node 的单独线程中运行某些东西,那么您需要生成一个单独的进程,您可以使用 child_process.fork() 然后使用 send().

In the renderer process you can create Web Workers, and those will run in their own threads, however Node integration will be disabled in those Web Workers because Node isn't thread-safe. So if you want to run something in a separate thread that uses Node then you'll need to spawn a separate process, you can do so with child_process.fork() and then communicate with the new process using send().

相关文章