I'm trying to optimize my code because it takes some time to run. The main part that slows it down is starting up puppeteer and navigating to the site and logging in. After this step I would ask for users input to a folder location to upload files.
The puppeteer setup takes about 8-10 seconds. So i'm trying to run that in parallel with getting users input to save time.
I'm not sure what the best way to communicate between child process is. After puppeteer loads it needs the folder location to run the next steps. So after the input process is complete it should send the info to the puppeteer process.
What I've done is once the input process is complete I would use
process.send({type: "upload", data: inputData})
Then in the main process I would receive it and send the data to the puppeteer process like
Main process index.js
const input = fork("./app.js");
const upload = fork("./upload.js");
input.on("message", function (chunk) {
const { type, data } = chunk;
switch (type) {
case "file":
console.log(data);
break;
case "upload":
upload.send(chunk);
break;
case "message":
console.log(data);
break;
default:
console.log(data);
break;
}
});
Is there an easier or more efficient way of communicating data between child process without having to send to to parent and then from there to the next child?