meteor logs -f: Properly close when we get an error from the logsForApp subscription

This commit is contained in:
Avital Oliver
2013-05-30 15:20:50 -07:00
parent ca8b0408ef
commit f260ce2887
2 changed files with 25 additions and 11 deletions

View File

@@ -534,18 +534,30 @@ _.extend(Meteor._LivedataConnection.prototype, {
return handle;
},
_subscribeAndWait: function (/* arguments */) {
// options:
// - onLateError {Function(error)} called if an error was received after the ready event.
// (errors received before ready cause an error to be thrown)
_subscribeAndWait: function (name, args, options) {
var self = this;
var f = new Future();
var args = _.toArray(arguments);
var ready = false;
args = args || [];
args.push({
onReady: function () { f.return(); },
onError: function (e) { f.throw(e); }
onReady: function () {
ready = true;
f.return();
},
onError: function (e) {
if (!ready)
f.throw(e);
else
options && options.onLateError && options.onLateError(e);
}
});
self.subscribe.apply(self, args);
self.subscribe.apply(self, [name].concat(args));
return f.wait();
},
},
methods: function (methods) {
var self = this;

View File

@@ -58,10 +58,14 @@ var prettyCall = function (galaxy, name, args, messages) {
var prettySub = function (galaxy, name, args, messages) {
try {
var ret = galaxy._subscribeAndWait.apply(galaxy, [name].concat(args));
} catch (e) {
var onError = function (e) {
exitWithError(e, messages);
};
try {
var ret = galaxy._subscribeAndWait(name, args, {onLateError: onError});
} catch (e) {
onError(e);
}
return ret;
};
@@ -207,8 +211,6 @@ exports.logs = function (options) {
if (!ok)
throw new Error("Couldn't connect to logs mongodb.");
// XXX make this talk to a separate logReader service instead of
// ultraworld direcly
prettySub(logReader, "logsForApp", [options.app], {
"no-such-app": "No such app: " + options.app
});