-
Notifications
You must be signed in to change notification settings - Fork 123
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
[DX-324] full async plugins initialisation #795
Conversation
@@ -81,27 +81,28 @@ module.exports.init = function(pluginsToRegister, callback) { | |||
}; | |||
|
|||
const loadPlugin = function(plugin, cb) { | |||
const done = _.once(cb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows robustness against plugins that would erroneously call the done() callback multiple times:
https://github.com/opencomponents/oc-hobknob/blob/master/index.js#L25
const pluginCallback = plugin.callback || _.noop; | ||
pluginCallback(err); | ||
registered[plugin.name] = plugin.register.execute; | ||
done(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now the callback is called actually after the registration is completed
setTimeout(() => { | ||
flag = true; | ||
cb(); | ||
}, 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this artificial timeout, I am testing that the callback is actually called after the registration (test failed before the code change)
The reason here is an old design decision. I think that given the way plugins evolved, it makes much more sense to wait express to start after all the plugins are fully initialised.