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

v2 rework to promises #126

Merged
merged 1 commit into from
May 27, 2024
Merged

v2 rework to promises #126

merged 1 commit into from
May 27, 2024

Conversation

foxriver76
Copy link
Collaborator

Breaking Changes:

  • (foxriver76) Methods no longer work with callback, please check the methods according to the types.
  • (foxriver76) All methods with async postfix are now working renamed to methods without the postfix
    while the callback methods have been removed
  • (foxriver76) Renamed instanciatePlugin to instantiatePlugin
  • (foxriver76) renamed isPluginInstanciated to isPluginInstantiated

*/
init(pluginConfig, callback) {
init(pluginConfig) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make async? ... also for the other methods ... then simply throw

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? They are returning Promise<void> On type level how you achieve this on implementation is up to code of specific plugin, there it will likely be async. See https://github.com/ioBroker/plugin-base/pull/126/files#diff-91cd6348c12238c4c2afe46f71253579dbc43ddb1db8872b76bff80ff25025e2R34 for type level

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes... just personal preference and "the same as in other classes" ... I hate "new Promise.reject" constructions in the meantime :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally we have eslint rules which complain if you have async function without doing anything async thus I prefer new Promise for such scenarios 😀

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol ... ok ... strange ... the throw normally suppreses that ... but all good

try {
await this.init(pluginConfig);
await this.setActive(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code is not the same ... old code returned a boolean and only if that boolean is true (setActive is called with true ... so here better const success = await .... setActive(success)

... ok OORRR methiod is now throwing also in non error but unsuccesseffull cases ... also good, just needs to make clear in docs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeof callback === 'function' && callback();
})
try {
await instance.initPlugin(this.plugins[name].config, parentConfig)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same her e... init not successfull ... needs to always throw

async initPlugins(parentConfig) {
for (const [pluginName, plugin] of Object.entries(this.plugins)) {
if (!plugin.instance) return;
await this.initPlugin(pluginName, parentConfig);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing them sequencially is ok ... could also be done in oparallel as before

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also go for promise.all but I guess it won't have an significant impact. Okay rn we only have sentry but also in general. If you want I can change but I would personally keep it.

@Apollon77 Apollon77 self-requested a review May 26, 2024 11:47
@foxriver76 foxriver76 merged commit 9b8e53a into master May 27, 2024
23 checks passed
@foxriver76 foxriver76 deleted the v2 branch May 27, 2024 06:01
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