1'use strict' 2 3const childProcess = require('child_process') 4 , childModule = require.resolve('./child/index') 5 6 7function fork (forkModule, workerOptions) { 8 // suppress --debug / --inspect flags while preserving others (like --harmony) 9 let filteredArgs = process.execArgv.filter(function (v) { 10 return !(/^--(debug|inspect)/).test(v) 11 }) 12 , options = Object.assign({ 13 execArgv : filteredArgs 14 , env : process.env 15 , cwd : process.cwd() 16 }, workerOptions) 17 , child = childProcess.fork(childModule, process.argv, options) 18 19 child.on('error', function() { 20 // this *should* be picked up by onExit and the operation requeued 21 }) 22 23 child.send({ owner: 'farm', module: forkModule }) 24 25 // return a send() function for this child 26 return { 27 send : child.send.bind(child) 28 , child : child 29 } 30} 31 32 33module.exports = fork 34