after startup, Meteor.startup(c) should call c now

This was the client behavior and is now the server behavior as well.

Fixes #2239.
This commit is contained in:
David Glasser
2014-06-18 17:02:03 -07:00
parent d180f9b02a
commit 4bec4877e3
4 changed files with 31 additions and 6 deletions

View File

@@ -75,3 +75,12 @@ Tinytest.add("environment - helpers", function (test) {
Meteor._delete(x, "a");
test.equal(x, {});
});
Tinytest.add("environment - startup", function (test) {
// After startup, Meteor.startup should call the callback immediately.
var called = false;
Meteor.startup(function () {
called = true;
});
test.isTrue(called);
});

View File

@@ -1,3 +1,8 @@
Meteor.startup = function (callback) {
__meteor_bootstrap__.startup_hooks.push(callback);
if (__meteor_bootstrap__.startupHooks) {
__meteor_bootstrap__.startupHooks.push(callback);
} else {
// We already started up. Just call it now.
callback();
}
};

View File

@@ -23,7 +23,7 @@ var configJson =
// Set up environment
__meteor_bootstrap__ = {
startup_hooks: [],
startupHooks: [],
serverDir: serverDir,
configJson: configJson };
__meteor_runtime_config__ = { meteorRelease: configJson.meteorRelease };
@@ -161,8 +161,14 @@ Fiber(function () {
func.call(global, Npm, Assets); // Coffeescript
});
// run the user startup hooks.
_.each(__meteor_bootstrap__.startup_hooks, function (x) { x(); });
// run the user startup hooks. other calls to startup() during this can still
// add hooks to the end.
while (__meteor_bootstrap__.startupHooks.length) {
var hook = __meteor_bootstrap__.startupHooks.shift();
hook();
}
// Setting this to null tells Meteor.startup to call hooks immediately.
__meteor_bootstrap__.startupHooks = null;
// find and run main()
// XXX hack. we should know the package that contains main.

View File

@@ -66,7 +66,7 @@ var load = function (options) {
// will get refactored before too long. Note that
// __meteor_bootstrap__.require is no longer provided.
var env = {
__meteor_bootstrap__: { startup_hooks: [] },
__meteor_bootstrap__: { startupHooks: [] },
__meteor_runtime_config__: { meteorRelease: options.release }
};
@@ -83,7 +83,12 @@ var load = function (options) {
ret = image.load(env);
// Run any user startup hooks.
_.each(env.__meteor_bootstrap__.startup_hooks, function (x) { x(); });
while (env.__meteor_bootstrap__.startupHooks.length) {
var hook = env.__meteor_bootstrap__.startupHooks.shift();
hook();
}
// Setting this to null tells Meteor.startup to call hooks immediately.
env.__meteor_bootstrap__.startupHooks = null;
});
if (messages.hasMessages()) {