#fork from child process how to target file?
1 messages · Page 1 of 1 (latest)
absolute path to file
can I do like
./worker.js they are in the same path
no
Thank you, it's working, but have a question
const workerFilePath = path.join('./src/main/', 'worker.js')
this works for linux also ? (it convert?)
hmmmm ... do i need to use app.path? something like that?
you need to use __dirname
can't make it work
const workerFilePath = path.join(__dirname, 'worker.js')
result: Cannot find module \out\main\worker.js
what am i doing wrong?
you dont have files in production folder
i'm testing with npm run dev
why the files doesn't go there?
i didn't move anything...
let's start from the beginning
i created this to test a fork
./index.js
const { fork } = require('child_process')
ipcMain.on('start-task', () => {
const numbers = Array.from({ length: 10 }, (_, index) => index + 1)
const clusters = 3 // Number of clusters/workers
const numberChunks = []
const chunkSize = Math.ceil(numbers.length / clusters)
for (let i = 0; i < numbers.length; i += chunkSize) {
const chunk = numbers.slice(i, i + chunkSize)
numberChunks.push(chunk)
}
const workerFilePath = path.join(__dirname, 'worker.js')
for (let i = 0; i < numberChunks.length; i++) {
const worker = fork(workerFilePath)
const chunk = numberChunks[i]
worker.send({ chunk })
}
})
./worker.js
process.on('message', (message) => {
const { chunk } = message
console.log('Received chunk:', chunk)
})
npm run dev -> result: Cannot find module \out\main\worker.js
its question to your project structure and packagers/bundlers
files didnt magically goes from folder A to folder B
i created the file... what do you mean with folder A and B? I used Electron Vite to create the project, I don't know if that helps
you also need to setup vite
for new files
so he process worker.js file as well
i am not using vite so i cant help you with it
But I have more files and they work properly , my utility folder have functions inside and all it's working :/
because you require them
owww .... thanks, i will try to find a solution
correct