From cd049586ea42aa05c5eaffd0d0d932e3c22aa98f Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 8 Jan 2016 11:07:58 -0800 Subject: [PATCH] Centralize state updates in Process --- console/src/modules/hf-process.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/console/src/modules/hf-process.js b/console/src/modules/hf-process.js index 537f2a81ad..1bdade3b1f 100755 --- a/console/src/modules/hf-process.js +++ b/console/src/modules/hf-process.js @@ -167,7 +167,8 @@ Process.prototype = extend(Process.prototype, { } catch (e) { console.log("Got error starting child process for " + this.name, e); this.child = null; - this.state = ProcessStates.STOPPED; + this.updateState(ProcessStates.STOPPED); + return; } if (logStdout != 'ignore') { @@ -195,10 +196,10 @@ Process.prototype = extend(Process.prototype, { this.child.on('error', this.onChildStartError.bind(this)); this.child.on('close', this.onChildClose.bind(this)); - this.state = ProcessStates.STARTED; - console.log("Child process started"); - this.emit('state-update', this); + console.log("Child process started"); + this.updateState(ProcessStates.STARTED); + this.emit('logs-updated'); }, stop: function() { if (this.state != ProcessStates.STARTED) { @@ -212,7 +213,14 @@ Process.prototype = extend(Process.prototype, { } this.state = ProcessStates.STOPPING; - this.emit('state-update', this); + updateState: function(newState) { + if (this.state != newState) { + this.state = newState; + this.emit('state-update', this); + return true; + } + return false; + }, }, // Events