You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
904 B

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