From c5efe36bced47653e8726d41d25349603cac01c4 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Fri, 14 Feb 2014 01:06:18 -0800 Subject: [PATCH] Ensure we don't double-return through runFuture --- tools/run-app.js | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/tools/run-app.js b/tools/run-app.js index 4d594655f2..390636783c 100644 --- a/tools/run-app.js +++ b/tools/run-app.js @@ -359,8 +359,7 @@ _.extend(AppRunner.prototype, { // The existence of this future makes the fiber break out of its loop. self.exitFuture = new Future; - if (self.runFuture) - self.runFuture['return']({ outcome: 'stopped' }); + self._runFutureReturn({ outcome: 'stopped' }); self.exitFuture.wait(); self.exitFuture = null; @@ -438,7 +437,7 @@ _.extend(AppRunner.prototype, { return { outcome: 'stopped', bundleResult: bundleResult }; if (self.runFuture) throw new Error("already have future?"); - self.runFuture = new Future; + var runFuture = self.runFuture = new Future; // Run the program var appProcess = new AppProcess({ @@ -448,14 +447,12 @@ _.extend(AppRunner.prototype, { mongoUrl: self.mongoUrl, oplogUrl: self.oplogUrl, onExit: function (code, signal) { - if (self.runFuture) { - self.runFuture['return']({ - outcome: 'terminated', - code: code, - signal: signal, - bundleResult: bundleResult - }); - } + self._runFutureReturn({ + outcome: 'terminated', + code: code, + signal: signal, + bundleResult: bundleResult + }); }, program: self.program, onListen: function () { @@ -478,19 +475,17 @@ _.extend(AppRunner.prototype, { watcher = new watch.Watcher({ watchSet: watchSet, onChange: function () { - if (self.runFuture) { - self.runFuture['return']({ - outcome: 'changed', - bundleResult: bundleResult - }); - } + self._runFutureReturn({ + outcome: 'changed', + bundleResult: bundleResult + }); } }); } // Wait for either the process to exit, or (if watchForChanges) a // source file to change. Or, for stop() to be called. - var ret = self.runFuture.wait(); + var ret = runFuture.wait(); self.runFuture = null; self.proxy.setMode("hold"); @@ -501,6 +496,15 @@ _.extend(AppRunner.prototype, { return ret; }, + _runFutureReturn: function (value) { + var self = this; + if (!self.runFuture) + return; + var runFuture = self.runFuture; + self.runFuture = null; + runFuture['return'](value); + }, + _fiber: function () { var self = this;