Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make spawning super fast! #190

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: ignore subcomandante and use child_process
richardschneider authored and dryajov committed Mar 23, 2018

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 888e330ab9d4ba93c21288187efcd879b4e33f75
45 changes: 45 additions & 0 deletions src/subcomandante-lite.js
Original file line number Diff line number Diff line change
@@ -0,0 +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
2 changes: 1 addition & 1 deletion src/utils/exec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const run = require('subcomandante')
const run = require('./subcomandante-lite')
const once = require('once')
const debug = require('debug')
const log = debug('ipfsd-ctl:exec')