Skip to content
Advertisement

Should I use worker or child processes to run my function?

I have two files, main.js and job.js. When a button is clicked in main.js, I want a new, seperate process of the function in job.js to run.

What this process does is launch a new puppeteer browser instance. When the stop button is clicked, this process should be killed by pid. (For this we use process.kill(child.pid)?)

So would I want to use a worker or child process, and if any of those two, how would I implement it so it runs this function?

Important note: every time the start button is clicked, I would like a new process running the function to be started, so the specific process with that pid can be killed.

Advertisement

Answer

I suggest you to use a wrapper module for the child_process module. Example usage with execa module.

Main.js

JavaScript

This should give you an idea on how to implement it. I suggest to use child_process or any wrapper module. ^^

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement