Daniel Stephens
Daniel Stephens

Reputation: 3219

How to use Electron remote with a helper process?

I read a lot about the main/renderer processes in Electron and to me it seems neither of them is the right place for my heavy I/O based task, so I am considering to use an additional process. I got this feeling confirmed after reading this outdated medium blog Deep dive into Electron’s main and renderer processes, which states:

So where do I do CPU intensive work?

I used to think the main process is the ideal place for “heavy lifting” because it wouldn’t block the UI. That’s wrong actually — if you do CPU intensive work in the main process, it’ll lock up all your renderer processes (and give you the infamous beachball on macOS). So CPU intensive tasks should run in a separate process

Unfortunately it is from 2016 and the API slightly changed. Unfortunately I can't find any updated example. I found of course require("electron").remote, but I miss some examples how to spawn an additional process. Does anyone have a keyword I can look for?

I use Electron 9.1.0 and Node 12.8.0. LTS.

Upvotes: 3

Views: 327

Answers (1)

Daniele Ricci
Daniele Ricci

Reputation: 15797

First of all we need to distinguish a CPU intensive task from a heavy I/O task; with a good use of native asynchronous mechanisms JavaScript shouldn't have problems dealing with heavy I/O tasks.

Quite different story is when we are speaking about CPU intensive tasks which have the problem as said in the blog you referenced.

To deal with CPU intensive tasks you could find useful Workers (or the Node.js implementation: Worker threads)

Upvotes: 3

Related Questions