@@ -319,12 +319,15 @@ module.exports = (api, options) => {
319
319
let child
320
320
let firstBundleCompleted = false
321
321
// Function to kill Electron process
322
- const killElectron = ( ) => {
323
- if ( ! child ) {
324
- return
322
+ const killElectron = ( ) => new Promise ( resolve => {
323
+ if ( ! child || child . killed ) {
324
+ return resolve ( )
325
325
}
326
326
327
327
const currentChild = child
328
+ currentChild . on ( 'exit' , ( ) => {
329
+ resolve ( )
330
+ } )
328
331
329
332
// Attempt to kill gracefully
330
333
if ( process . platform === 'win32' ) {
@@ -340,7 +343,7 @@ module.exports = (api, options) => {
340
343
currentChild . kill ( 'SIGKILL' )
341
344
}
342
345
} , 2000 )
343
- }
346
+ } )
344
347
345
348
// Initial start of Electron
346
349
startElectron ( )
@@ -379,14 +382,19 @@ module.exports = (api, options) => {
379
382
} )
380
383
}
381
384
382
- function launchElectron ( ) {
385
+ async function launchElectron ( ) {
383
386
firstBundleCompleted = true
384
387
// Don't exit process when electron is killed
385
388
if ( child ) {
386
389
child . removeListener ( 'exit' , onChildExit )
387
390
}
388
391
// Kill existing instances
389
- killElectron ( )
392
+ let waitTimeout = setTimeout ( ( ) => {
393
+ // If killing Electron takes over 500ms:
394
+ info ( 'Waiting for Electron to exit...' )
395
+ } , 500 )
396
+ await killElectron ( )
397
+ clearTimeout ( waitTimeout )
390
398
// Don't launch if a new background file is being bundled
391
399
queuedBuilds --
392
400
if ( queuedBuilds > 0 ) return
0 commit comments