{"action":"created","issue":{"url":"https://api.github.com/repos/hapijs/discuss/issues/154","labels_url":"https://api.github.com/repos/hapijs/discuss/issues/154/labels{/name}","comments_url":"https://api.github.com/repos/hapijs/discuss/issues/154/comments","events_url":"https://api.github.com/repos/hapijs/discuss/issues/154/events","html_url":"https://github.com/hapijs/discuss/issues/154","id":104908567,"number":154,"title":"Correct use of server.dependency callback","user":{"login":"damonmcminn","id":5415900,"avatar_url":"https://avatars.githubusercontent.com/u/5415900?v=3","gravatar_id":"","url":"https://api.github.com/users/damonmcminn","html_url":"https://github.com/damonmcminn","followers_url":"https://api.github.com/users/damonmcminn/followers","following_url":"https://api.github.com/users/damonmcminn/following{/other_user}","gists_url":"https://api.github.com/users/damonmcminn/gists{/gist_id}","starred_url":"https://api.github.com/users/damonmcminn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damonmcminn/subscriptions","organizations_url":"https://api.github.com/users/damonmcminn/orgs","repos_url":"https://api.github.com/users/damonmcminn/repos","events_url":"https://api.github.com/users/damonmcminn/events{/privacy}","received_events_url":"https://api.github.com/users/damonmcminn/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hapijs/discuss/labels/question","name":"question","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-04T15:06:14Z","updated_at":"2015-09-04T15:25:28Z","closed_at":null,"body":"I am writing a plugin in the form:\r\n\r\n```javascript\r\nfunction foo(plugin, options, next) {\r\n\r\n  plugin.dependency('bar', function(server, done) {\r\n\r\n    server.expose('foo', 'bar');\r\n    \r\n    done();\r\n    next();\r\n    \r\n  });\r\n  \r\n}\r\n```\r\n\r\nThis causes the server to stall at startup. By executing the `next` callback in it's original scope, the server does not stall:\r\n\r\n```javascript\r\nfunction foo(plugin, options, next) {\r\n\r\n  plugin.dependency('bar', function(server, done) {\r\n\r\n    server.expose('foo', 'bar');\r\n    done();\r\n    \r\n  });\r\n\r\n  // execute next() before done()\r\n  return next();\r\n  \r\n}\r\n```\r\n\r\nI am using Glue to register plugins etc:\r\n\r\n```javascript\r\nGlue.compose(manifest, function(err, server) {\r\n\r\n  // do stuff with server.plugins.foo\r\n  server.start();\r\n  \r\n});\r\n```\r\n\r\nThe issue I'm encountering is that server startup stalls in the first instance but `server.plugins.foo` is undefined in the second.\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/hapijs/discuss/issues/comments/137766066","html_url":"https://github.com/hapijs/discuss/issues/154#issuecomment-137766066","issue_url":"https://api.github.com/repos/hapijs/discuss/issues/154","id":137766066,"user":{"login":"devinivy","id":3150233,"avatar_url":"https://avatars.githubusercontent.com/u/3150233?v=3","gravatar_id":"","url":"https://api.github.com/users/devinivy","html_url":"https://github.com/devinivy","followers_url":"https://api.github.com/users/devinivy/followers","following_url":"https://api.github.com/users/devinivy/following{/other_user}","gists_url":"https://api.github.com/users/devinivy/gists{/gist_id}","starred_url":"https://api.github.com/users/devinivy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devinivy/subscriptions","organizations_url":"https://api.github.com/users/devinivy/orgs","repos_url":"https://api.github.com/users/devinivy/repos","events_url":"https://api.github.com/users/devinivy/events{/privacy}","received_events_url":"https://api.github.com/users/devinivy/received_events","type":"User","site_admin":false},"created_at":"2015-09-04T15:25:28Z","updated_at":"2015-09-04T15:25:28Z","body":"The callback that goes into `server.dependency` is akin to using `server.after()`, so it's actually called during `onPreStart` and not during plugin registration.  It's only called if the server is started.  The dependencies listed ensure that the `server.dependency` callbacks are called in the correct order."}}