Skip to content
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

Merged
merged 3 commits into from
Dec 22, 2017
Merged

[DX-324] full async plugins initialisation #795

merged 3 commits into from
Dec 22, 2017

Conversation

matteofigus
Copy link
Member

@matteofigus matteofigus commented Dec 21, 2017

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.

@@ -81,27 +81,28 @@ module.exports.init = function(pluginsToRegister, callback) {
};

const loadPlugin = function(plugin, cb) {
const done = _.once(cb);
Copy link
Member Author

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);
Copy link
Member Author

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);
Copy link
Member Author

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)

@matteofigus matteofigus merged commit 4b608a6 into master Dec 22, 2017
@matteofigus matteofigus deleted the init-async branch December 22, 2017 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants