mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-19 00:23:25 +02:00
New rewrite of provider. By moving to promises we should no longer have issues with double-quits.
This commit is contained in:
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user