mirror of
https://github.com/openstf/stf
synced 2025-10-05 02:29:26 +02:00
Let CLI know when procs die.
This commit is contained in:
parent
60143b28cb
commit
24825ff7fc
2 changed files with 81 additions and 28 deletions
36
lib/util/procutil.js
Normal file
36
lib/util/procutil.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
var util = require('util')
|
||||
var cp = require('child_process')
|
||||
|
||||
var Promise = require('bluebird')
|
||||
|
||||
function ExitError(code) {
|
||||
Error.call(this, util.format('Exit code "%d"', code))
|
||||
this.name = 'ExitError'
|
||||
this.code = code
|
||||
Error.captureStackTrace(this, ExitError)
|
||||
}
|
||||
|
||||
util.inherits(ExitError, Error)
|
||||
|
||||
// Export
|
||||
module.exports.ExitError = ExitError
|
||||
|
||||
// Export
|
||||
module.exports.fork = function() {
|
||||
var args = arguments
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
var proc = cp.fork.apply(cp, args)
|
||||
|
||||
proc.on('error', function(err) {
|
||||
reject(err)
|
||||
proc.kill()
|
||||
})
|
||||
|
||||
proc.on('exit', function(code) {
|
||||
if (code > 0) {
|
||||
reject(new ExitError(code))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue