Skip to content

Commit

Permalink
chore: liniting
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jan 28, 2018
1 parent 6cb44ec commit bf05306
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions src/subcomandante-lite.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
'use strict'

const runner = require('child_process')
const debug = require('debug')('subchild')

const children = []

function removeChild (child) {
const i = children.indexOf(child)
if (i !== -1) {
children.slice(i, 1)
}
}

function killAll () {
debug('killing all children')
let child
while((child = children.shift()) !== undefined) {
debug(child.pid, 'killing')
child.kill();
}
}

process.once('error', killAll)
process.once('exit', killAll)
process.once('SIGTERM', killAll)
process.once('SIGINT', killAll)

function run (cmd, args, opts) {
const child = runner.execFile(cmd, args, opts)
debug(child.pid, 'new')

children.push(child);
child.once('error', () => {
debug(child.pid, 'error')
removeChild(child)
})
child.once('exit', () => {
debug(child.pid, 'exit')
removeChild(child);
})
return child
}

module.exports = run
'use strict'

const runner = require('child_process')
const debug = require('debug')('subchild')

const children = []

function removeChild (child) {
const i = children.indexOf(child)
if (i !== -1) {
children.slice(i, 1)
}
}

function killAll () {
debug('killing all children')
let child
while ((child = children.shift()) !== undefined) {
debug(child.pid, 'killing')
child.kill()
}
}

process.once('error', killAll)
process.once('exit', killAll)
process.once('SIGTERM', killAll)
process.once('SIGINT', killAll)

function run (cmd, args, opts) {
const child = runner.execFile(cmd, args, opts)
debug(child.pid, 'new')

children.push(child)
child.once('error', () => {
debug(child.pid, 'error')
removeChild(child)
})
child.once('exit', () => {
debug(child.pid, 'exit')
removeChild(child)
})
return child
}

module.exports = run

0 comments on commit bf05306

Please sign in to comment.