問題描述
如果我制作了一個電子應(yīng)用程序,我很難在谷歌上搜索我將如何進(jìn)行多線程.會是網(wǎng)絡(luò)工作者嗎?
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?
推薦答案
在渲染進(jìn)程中你可以創(chuàng)建Web Workers,并且這些將在自己的線程中運(yùn)行,但是 在這些 Web Workers 中將禁用節(jié)點(diǎn)集成 因?yàn)?Node 不是線程安全的.因此,如果您想在使用 Node 的單獨(dú)線程中運(yùn)行某些東西,那么您需要生成一個單獨(dú)的進(jìn)程,您可以使用 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()
.
這篇關(guān)于電子框架是否允許通過網(wǎng)絡(luò)工作者進(jìn)行多線程?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!