Open VladimirKalachikhin opened 3 weeks ago
@panaaj any ideas?
The issue is due to calling getFeatures()
synchronously in the start up function.
It fails because the plugin manager is still starting plugins and the ability to return a list of plugins is not yet available.
A work around for invoking getFeatures()
in the plugin start()
function is to use setTimeout()
.
start() {
setTimeout( async () => await server.getFeatures(), 500)
}
Will add a test to getFeatures()
so it can fail gracefully and throw a meaningful error to the caller.
A real workaround is:
setImmediate(()=>app.getFeatures());
but it's pointless.
The real code could be
setImmediate(() => {let features = app.getFeatures();});
but!:
setImmediate(()=>{let features = app.getFeatures(); app.debug(features instanceof Promise)});
In fact .getFeatures() return Promise when as the documentation says "Returns an object detailing the available APIs and Plugins."
OK, if the .getFeatures() returns Promise instead result, then the code should be:
app.getFeatures().then((features)=>{app.debug('features list:',features)});
but it's get TypeError: app.getPluginsList is not a function That is the problem.
So a real real workaround is:
setImmediate(() => {app.getFeatures().then((features)=>{app.debug('features list:',features)});});
That is, to start the asynchronous function only on the next turn of the main cycle. It seems to me that this is nonsense.
This is kinda tricky: plugin A provides feature 1 if there is feature 2 available and feature 2 is provided by plugin B, that needs to be started. Somewhat similar to systemd dependencies with requires
and wants
.
We have already a similar method for plugins to "announce" properties:
The semantic difference to regular events is that listeners get the set of all emitted values since server startup, not just single values. A poor man's event broker with retain = true, if you will.
We could change the feature detection api to use app properties API, forcing plugins to react to features coming available.
This would also cover the case where a plugin providing a feature is activated later, after server startup.
Signal K Server version 2.8.3
The server plugin function app.getFeatures does not work. Code:
Result: