Wrap some CLI functions in a Fiber

This commit is contained in:
Avital Oliver
2013-01-25 18:47:27 -08:00
parent 2551d88014
commit d2319bc134
3 changed files with 27 additions and 2 deletions

21
app/lib/fiber-helpers.js Normal file
View File

@@ -0,0 +1,21 @@
// node (v8) defaults to only recording 10 lines of stack trace.
// this becomes especially bad when using fibers, since you get deeper
// stack traces that would have been split up between different callbacks
//
// this only affects the `meteor` executable, not server code on
// meteor apps.
Error.stackTraceLimit = Infinity; // http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
var Fiber = require("fibers");
// runs a function within a fiber. we wrap the entry point into meteor.js into a fiber
// but if you use callbacks that call synchronous code you need to wrap those as well.
//
// NOTE: It's probably better to not use callbacks. Instead you can
// use Futures to generate synchronous equivalents.
exports.inFiber = function(func) {
return function() {
new Fiber(func).run();
};
};

View File

@@ -13,6 +13,7 @@ var files = require(path.join(__dirname, '..', 'lib', 'files.js'));
var _ = require('underscore');
var keypress = require('keypress');
var child_process = require('child_process');
var inFiber = require(path.join(__dirname, '..', 'lib', 'fiber-helpers.js')).inFiber;
//
// configuration
@@ -352,6 +353,8 @@ var read_password = function (callback) {
var with_password = function (site, callback) {
var check_url = "https://" + DEPLOY_HOSTNAME + "/has_password/" + site;
callback = inFiber(callback);
request(check_url, function (error, response, body) {
if (error || response.statusCode !== 200) {
callback();

View File

@@ -11,6 +11,7 @@ var updater = require(path.join(__dirname, '..', 'lib', 'updater.js'));
var bundler = require(path.join(__dirname, '..', 'lib', 'bundler.js'));
var mongo_runner = require(path.join(__dirname, '..', 'lib', 'mongo_runner.js'));
var mongoExitCodes = require(path.join(__dirname, '..', 'lib', 'mongo_exit_codes.js'));
var inFiber = require(path.join(__dirname, '..', 'lib', 'fiber-helpers.js')).inFiber;
var _ = require('underscore');
@@ -601,7 +602,7 @@ exports.run = function (app_dir, bundle_opts, port, once, settingsFile) {
}
};
var restart_server = function () {
var restart_server = inFiber(function () {
Status.running = false;
Status.listening = false;
if (server_handle)
@@ -700,7 +701,7 @@ exports.run = function (app_dir, bundle_opts, port, once, settingsFile) {
}});
}
};
};
});
var mongo_err_count = 0;