Skip to content

Commit

Permalink
Move checkNewProcess to core-host initHostProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
Jashepp committed Feb 13, 2017
1 parent 2ecb897 commit d7b51c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
24 changes: 4 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
const path = require('path');

const _ = require(path.resolve(__dirname,'./lib/underscore-with-mixins'));
const ipcTransport = require(path.resolve(__dirname,'./lib/ipc-transport'));
const coreClient = require(path.resolve(__dirname,'./lib/core-client'));
const coreHost = require(path.resolve(__dirname,'./lib/core-host'));
const coreProcessManager = require(path.resolve(__dirname,'./lib/core-process-manager'));
Expand Down Expand Up @@ -54,22 +53,7 @@ requireWorkerObj.getStackFiles = function getStackFiles(){
return result;
};

const checkNewProcess = ()=>{
if(require.main===module && process.argv.length===4 && process.argv[2]==='--rwProcess'){
var ipcTransportID = process.argv[3];
var transport = ipcTransport.create({
id: ipcTransportID,
parent: true
});
var transportEvents = transport.createMessageEventEmitter();
transportEvents.on('processReady?',()=>{
transportEvents.send('processReady!');
});
transportEvents.on('requireHost',(hostOptions)=>{
new coreHost.requireWorkerHost(hostOptions);
});
transportEvents.send('processReady!');
}
};

checkNewProcess();
// Check if the current process is a require-worker host
if(require.main===module && process.argv.length===4 && process.argv[2]==='--rwProcess'){
coreHost.initHostProcess({ ipcTransportID:process.argv[3] });
}
16 changes: 15 additions & 1 deletion lib/core-host.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* global exports, Promise */
"use strict";

const path = require('path');
const eventEmitter = require('events');

const _ = require('./underscore-with-mixins');
Expand Down Expand Up @@ -71,3 +70,18 @@ host.prototype = {
});
}
};

exports.initHostProcess = function({ ipcTransportID }){
var transport = ipcTransport.create({
id: ipcTransportID,
parent: true
});
var transportEvents = transport.createMessageEventEmitter();
transportEvents.on('processReady?',()=>{
transportEvents.send('processReady!');
});
transportEvents.on('requireHost',(hostOptions)=>{
new host(hostOptions);
});
transportEvents.send('processReady!');
};

0 comments on commit d7b51c5

Please sign in to comment.