electron-remote
electron-remote copied to clipboard
Send IPC message from main process to a reader in the task pool
Hello,
I'm trying to send a message from the main process to all the render processes in the task pool.
Now I'm sending the message using the standard electron ipcMain.send()
but unfortunately the message is not received by the background render processes.
Any idea on how to make it work?
Can you talk more about what you're trying to do? This is probably a pretty race-condition'y thing to do
Hi @paulcbetts, I'm building a file uploader to upload files to S3. I'm using electron-remote to spawn a worker for each file in the upload queue.
FileUploader = ElectronRemote.requireTaskPool('./electron/workers/uploadWorker', 4, 24*60*60*1000);
the code above is for the upload
// send to the upload workers a file to upload
private async doUpload(file: ContentFile) {
// it doesn't return until FileUploader uploaded the data,
// the queue is blocked by the evaporate uploading process that is synchronous, wait until an
// upload is success or error
await FileUploader.doUpload(file);
}
My idea is to send a message from the main thread (upload manager) to all the workers in the task pool in order to pause/resume the uploads.
Maybe I'm approaching the problem in the wrong way. How can I implement a bidirectional communication between the workers and the upload manager?
Maybe I'm approaching the problem in the wrong way. How can I implement a bidirectional communication between the workers and the upload manager?
I don't think you're approaching it wrong, I just think we don't have a super great solution for this right now. How would you picture that API to work? (I have some ideas but I'm not sure if other people would grok them)
I don't think you're approaching it wrong, I just think we don't have a super great solution for this right now. How would you picture that API to work? (I have some ideas but I'm not sure if other people would grok them)
The ideal for me would be to have an API similar to the one exposed by the default ipc
module of electron, which ideally allows to subscribe to one or more events (ipcRenderer.on(channel, listener)
). Do you think this kind of approach would also work for async function calls?
Did you have something else in mind?
@paulcbetts Any idea ?