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

setObject() function: callback not working as intended. #474

Closed
Mic-M opened this issue Jan 9, 2020 · 7 comments
Closed

setObject() function: callback not working as intended. #474

Mic-M opened this issue Jan 9, 2020 · 7 comments
Labels

Comments

@Mic-M
Copy link
Contributor

Mic-M commented Jan 9, 2020

Hi,
This issue is about the setObject() function: setObject(id, obj, callback);

Per the documentation, we would expect that a certain function, which is provided to the callback parameter of "setObject()", is executed AFTER completion of setObject(). However, it seems that this is not working.
Please see ioBroker Forum Thread [Vorlage] Skript: Erstellen von User-Datenpunkten.

This forum post initially mentions an issue with setObject. If you scroll further down, you'll see more info on it.

Per my tests I have made, I can confirm that the callback is being executed like immediately, and not after setObject() function completion.
My environment: JavaScript adapter version: 4.3.4 // js-controller 2.2.7

Thanks guys! Let me know if you need any further info or tests.

@Apollon77
Copy link
Contributor

Per my tests I have made, I can confirm that the callback is being executed like immediately, and not after setObject() function completion.

This is not completely correct ... The topic is that new Objects/States are registered by JavaScript Adapter when they are published in the system. This happens asynchronously after the setObject.

I think it is no problem to already store the object data when the callitself was successull...

@Apollon77 Apollon77 added the bug label Jan 9, 2020
@AlCalzone
Copy link
Collaborator

I'm confused... What is correct now?

@Mic-M
Copy link
Contributor Author

Mic-M commented Jan 10, 2020

Hi @Apollon77,
I don't understand either. Per node.js:

Node.js, being an asynchronous platform, doesn't wait around for things like file I/O to finish - Node.js uses callbacks. A callback is a function called at the completion of a given task

The given task is to set an object through setObject(), and at the completion (which means NOT at the beginning or while executing), the callback() should apply. I may be wrong with my understanding, and look forward to further explanation. Thanks.

@Apollon77
Copy link
Contributor

You are all right and I wanted to do exactly the same ... I just described the reason for it and provided a potential solution. So, yes it is a bug :-)

@Mic-M
Copy link
Contributor Author

Mic-M commented Jan 10, 2020

Many thanks @Apollon77. Now I do fully understand your previous response :-)

@GermanBluefox
Copy link
Contributor

I still do not understand, what is wrong

@Apollon77
Copy link
Contributor

@GermanBluefox setObject is only calling setForeignObject but is not registering the obejct in the internal "objects cache from javascript adapter". This "registration only happens once the objectChange event is coming in. Because of the async nature this will normally happen AFTER the callback of the setObject is called ... so when you want to access the object directly in the callback you might get an error because it is missing in the internal object cache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants