1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 02:09:32 +02:00

New rewrite of provider. By moving to promises we should no longer have issues with double-quits.

This commit is contained in:
Simo Kinnunen 2014-02-04 15:42:52 +09:00
parent 8a23b37deb
commit adaf3da228
3 changed files with 232 additions and 270 deletions

View file

@ -34,3 +34,28 @@ module.exports.fork = function() {
})
})
}
// Export
module.exports.gracefullyKill = function(proc, timeout) {
function killer(signal) {
var deferred = Promise.defer()
function onExit() {
deferred.resolve()
}
proc.once('exit', onExit)
proc.kill(signal)
return deferred.promise.finally(function() {
proc.removeListener('exit', onExit)
})
}
return killer('SIGTERM')
.timeout(timeout)
.catch(function() {
return killer('SIGKILL')
.timeout(timeout)
})
}