Skip to content

Commit

Permalink
fix(dev command): failed terminating app
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Oct 1, 2019
1 parent d3d55f6 commit e49721a
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions packages/@nodepack/service/src/commands/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,27 +115,41 @@ module.exports = (api, options) => {
}
}
terminated = true
terminating = null
})
}
}
}, 500)
)

/** @type {Promise} */
let terminatePromise

async function terminateApp () {
if (child && !terminated && terminating !== child) {
terminating = child
try {
const result = await terminate(child, api.getCwd())
if (result.error) {
throw result.error
}
child.kill('SIGINT')
return true
} catch (e) {
error(`Couldn't terminate process ${child.pid}: ${e}`)
terminatePromise = new Promise(async (resolve) => {
resolve(await killChild())
})
return terminatePromise
} else if (terminating) {
return terminatePromise
} else {
return terminated
}
}

async function killChild () {
try {
const result = await terminate(child, api.getCwd())
if (result.error) {
throw result.error
}
child.kill('SIGINT')
return true
} catch (e) {
error(`Couldn't terminate process ${child.pid}: ${e}`)
}
return terminated
}

const onExit = async () => {
Expand Down

0 comments on commit e49721a

Please sign in to comment.