mirror of https://github.com/status-im/metro.git
worker-farm/lib/fork.js: cleanup
Reviewed By: davidaurelio Differential Revision: D5002190 fbshipit-source-id: 07230f3e4fb059430124f44a82a928921904ed7b
This commit is contained in:
parent
c6a7491405
commit
62b6f4bdc5
|
@ -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';
|
||||
|
||||
function fork (forkModule) {
|
||||
var child = childProcess.fork(childModule, {
|
||||
env: process.env
|
||||
, cwd: process.cwd()
|
||||
})
|
||||
const childProcess = require('child_process');
|
||||
const childModule = require.resolve('./child/index');
|
||||
|
||||
child.send({ module: forkModule })
|
||||
function fork(forkModule: string) {
|
||||
const child = childProcess.fork(childModule, {
|
||||
env: process.env,
|
||||
cwd: process.cwd(),
|
||||
});
|
||||
|
||||
child.send({module: forkModule});
|
||||
|
||||
// return a send() function for this child
|
||||
return {
|
||||
send : function (data) {
|
||||
send(data: {}) {
|
||||
try {
|
||||
child.send(data)
|
||||
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,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 */
|
||||
|
@ -12,20 +14,14 @@ 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) {
|
||||
|
|
Loading…
Reference in New Issue