Skip to content Skip to sidebar Skip to footer

Asynchrony Issue On Electron

I'm currently working on an Electron.js app and I'm stuck on an asynchrony problem. I have three function (downdloadFile()) inside three if statements to be executed in sequence bu

Solution 1:

Where you currently console.log("RETURN") you can resolve a Promise which is returned by downloadFile. Then you can simply await the calls in your if branches (and pass async callback to ipcMain of course).

The structure in a more simple form would look like the followings

functiondoJob () {
  returnnewPromise((resolve, reject) => {
    setTimeout(() => {
      console.log('RETURN')
      resolve()
    }, 2000)
  })
}
// ipcMain.on('play', async (event, payload) => { ... })
(async () => {
  if (true) {
    awaitdoJob()
  }
  if (true) {
    awaitdoJob()
  }
})()

Solution 2:

I can see you are affecting launcherDir in all three times using it in the !if will always execute the first process even if it fails i.e the last if will be checking launcherDir + "\natives" + "\bin" or is this the desired behaviour if not i think all your if's will fail

Post a Comment for "Asynchrony Issue On Electron"