ioBroker.javascript icon indicating copy to clipboard operation
ioBroker.javascript copied to clipboard

Usage of cb-function does not work

Open neopholus opened this issue 3 years ago • 4 comments

I have some callback functions running. When restarting the script, those run until javascript-adapter is restarted. This behavior is also described here: https://github.com/ioBroker/ioBroker.javascript/blob/master/docs/en/javascript.md : If in the script some modules or functions are used with callbacks or cyclic calls, except setTimeout/setInterval, so they will be called again and again even if the new version of script exists or script is deleted.... To fix this feature restart the javascript adapter. You can use cb function to wrap you callback [...] to be sure, that no callback will be called if script is deleted or modified.

But unfortunately I cannot use the cb-function. cb-Function is underlined red when I type it in the TypeScript editor. When compiling, this error is shown: TypeScript compilation failed:[...] cb(function () { ^ ERROR: Cannot find name 'cb'. Is there an alternative or was the cb-function renamed? Or is it just a bug?

neopholus avatar Sep 18 '22 12:09 neopholus

@AlCalzone are there types missing?

Apollon77 avatar Sep 18 '22 14:09 Apollon77

Pretty sure. First time I've heard about this function

AlCalzone avatar Sep 19 '22 07:09 AlCalzone

Can I add the type myself in my code or is this something only AlCalzone can fix in the adapter code?

neopholus avatar Oct 02 '22 08:10 neopholus

Should be possible using

declare function cb(...): void;

(not sure about the arguments or the return type though, better double check that)

AlCalzone avatar Oct 03 '22 11:10 AlCalzone