New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add async init hook #560
Comments
we already have async support in the |
The lifecycle events don't allow you any control over the startup sequence. People need a way to run some code before the server actually starts up. |
Added in f93e789, pushed to NPM in v0.12.6. |
Sorry, I'm a bit confused on how to use this. Correct me if I'm wrong. In init.js I could: var init = function(cb){
geddy.beforeStart = function(next){
doSomeAsyncStuff(function(er){
if(!er) next();
});
}
} Is that right? If not, how? I don't see in the diff what geddy expects other than beforeStart to be a function. |
Don't wrap it in the init callback, just do On Thu, Mar 6, 2014 at 3:18 PM, Dan Finlay notifications@github.com wrote:
|
Oh, I may actually be wrong here. @mde How did you implement this? |
Mde just said in IRC:
So I think it's assignment, not a function. But in the init callback or not? |
Yeah, it looks like it's assignment. I don't think it should be in the init callback though. |
The app-loader requires the init.js file, and then immediately runs the exported init function, so you don't need to stick it in the init function, but it doesn't hurt if you do. |
Ugh, @ben-ng, you're totally right -- I didn't look closely enough. The async init is plenty early. It all runs as the app loads, and before the server starts. I haven't documented this stuff yet, so I'm actually kind of inclined to rip it out before people start depending on it. @FlySwatter, does that make sense to you? |
I have backed these changes out. The server doesn't start up until you call the continuation/callback passed into the async init, so you can do whatever setup you need there. Thanks @ben-ng for pointing it out. |
Currently if I need to perform an async operation before a
geddy
instance starts, I'd have to either wrap the geddy.start() function in a callback (doesn't work for clustered instances), or try something else hacky.Here was
mde
's thought:The text was updated successfully, but these errors were encountered: