javascript - Creating multiple invisible windows with different parameters in Electron -


description

i trying use invisible windows tasks/threads in electron. first create number of invisible windows in for-loop in main process. each window sends event dom-is-ready back. received in main process, event parameter (a path) sent window, creates array , sends array main process.

code

main process

for(let = 0; < paths.length; i++){     invpfwins[i] = new browserwindow({         width: 400,         height: 400,         show: false     });      invpfwins[i].loadurl(invispath);      invpfwins[i].webcontents.on('did-finish-load', function () {         invpfwins[i].show();     });     invpfwins[i].webcontents.opendevtools();  }  let = 0;  ipcmain.on('dom-is-ready', function (event) {     invpfwins[i].webcontents.send('start-read-files', paths[i], i++); });  ipcmain.on('files-read-done', function (event, output, id) {     console.log(output);     pflists[id] = output; }); 
  • paths array of paths sent invisible windows
  • invpfwins stores invisible windows created

invisible window

ipc.on('start-read-files', function (event, ppath, id) {     console.log("start signal received");     let retval = readfiles(ppath);      ipc.send('files-read-done', retval, id)     window.close() });  ipc.send('dom-is-ready'); console.log("dom-is-ready sent"); 

behaviour

the program not create error of time of invisible (not yet invisible) windows not terminate , don't send results. invisible windows send dom-is-ready event don't terminate not receive start-read-files event. think because of race condition, after created windows in loop can happen windows don't send dom-is-ready event in order created in. tried put code listens dom-is-ready event for-loop following error:

uncaught exception: error: object has been destroyed     @ error (native)     @ eventemitter.<anonymous> 

question

is guess race condition problem right? , how can solve that? feel not way of doing that, there better way in electron spawn tasks/threads these (i tried web workers node.js modules did not work there)?


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -