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()
}
})()
Post a Comment for "Asynchrony Issue On Electron"