mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
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:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user