Permalink
Browse files

worker-farm/lib/fork.js: cleanup

Reviewed By: davidaurelio

Differential Revision: D5002190

fbshipit-source-id: 07230f3e4fb059430124f44a82a928921904ed7b
  • Loading branch information...
jeanlauliac authored and facebook-github-bot committed May 4, 2017
1 parent 76d6f90 commit 2de6e546bdbc42075def43fb9d12def143c74224
@@ -51,7 +51,7 @@ function makeFarm(worker, methods, timeout, maxConcurrentWorkers) {
class Transformer {
_workers: {[name: string]: mixed};
_workers: {[name: string]: Function};
_transformModulePath: string;
_transform: (
transform: string,
@@ -5,6 +5,8 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
/* eslint-disable */
@@ -25,7 +27,7 @@ const extend = require('xtend')
, ProcessTerminatedError = require('errno').create('ProcessTerminatedError')
, MaxConcurrentCallsError = require('errno').create('MaxConcurrentCallsError')
function Farm (options, path) {
function Farm (options: {}, path: string) {
this.options = extend(DEFAULT_OPTIONS, options)
this.path = path
this.activeCalls = 0
@@ -5,31 +5,34 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
/* eslint-disable */
const childProcess = require('child_process')
, childModule = require.resolve('./child/index')
'use strict';
const childProcess = require('child_process');
const childModule = require.resolve('./child/index');
function fork (forkModule) {
var child = childProcess.fork(childModule, {
env: process.env
, cwd: process.cwd()
})
function fork(forkModule: string) {
const child = childProcess.fork(childModule, {
env: process.env,
cwd: process.cwd(),
});
child.send({ module: forkModule })
child.send({module: forkModule});
// return a send() function for this child
return {
send : function (data) {
try {
child.send(data)
} catch (e) {
// this *should* be picked up by onExit and the operation requeued
}
send(data: {}) {
try {
child.send(data);
} catch (e) {
// this *should* be picked up by onExit and the operation requeued
}
, child : child
}
},
child,
};
}
module.exports = fork
module.exports = fork;
@@ -5,27 +5,23 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
/* eslint-disable */
const Farm = require('./farm')
var farms = [] // keep record of farms so we can end() them if required
function farm (options, path, methods) {
if (typeof options == 'string') {
methods = path
path = options
options = {}
}
function farm(options: {}, path: string, methods: Array<string>): {[name: string]: Function} {
var f = new Farm(options, path)
, api = f.setup(methods)
farms.push({ farm: f, api: api })
// return the public API
return api
return (api: any)
}
function end (api, callback) {

0 comments on commit 2de6e54

Please sign in to comment.