mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 14:53:24 +02:00
Let CLI know when procs die.
This commit is contained in:
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))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user