update files

This commit is contained in:
nuintun 2015-12-04 17:58:01 +08:00
parent 1b8e084879
commit 12e9d713c5
3 changed files with 62 additions and 36 deletions

View File

@ -9,8 +9,20 @@ var Emulator = require('./emulator');
var emulator;
// thread
process.on('message', function (project){
process.on('message', function (message){
if (message.action === 'stop') {
if (emulator) {
emulator.stop();
}
process.exit();
return;
}
if (message.action === 'start') {
var stream;
var project = message.project;
if (emulator) {
emulator.stop();
@ -48,4 +60,5 @@ process.on('message', function (project){
data: signal.toString()
});
});
}
});

View File

@ -26,7 +26,13 @@ Emulator.prototype = {
},
stop: function (){
if (this.thread) {
this.thread.kill('SIGTERM');
this.thread.kill('SIGKILL');
['stdin', 'stdout', 'stderr'].forEach(function (stream){
this.thread[stream].removeAllListeners();
}, this);
this.thread = null;
}
},
exec: function (){

View File

@ -19,7 +19,9 @@ function killThread(name){
var thread = threads[name];
if (thread && thread.connected) {
thread.kill('SIGTERM');
thread.send({
action: 'stop'
});
delete threads[name];
}
@ -28,8 +30,7 @@ function killThread(name){
module.exports = {
start: function (){
ipc.on('emulator', function (event, project, action){
var key = project.name + '-' + project.command.name;
var thread = threads[key];
var thread = threads[project.name];
switch (action) {
case 'start':
@ -58,13 +59,19 @@ module.exports = {
delete project.env;
thread.send(project);
thread.send({
action: 'start',
project: project
});
threads[project.name] = thread;
} else {
delete project.env;
thread.send(project);
thread.send({
action: 'start',
project: project
});
}
break;
case 'stop':