I might be a bit thick today but I don't seem to be able to find any magic to allow the RED.nodes.registerType callback function to be an async function?
I have a function call in it that I would ideally like to await and that has to be async.
The only other approach is a major re-write to push all of the follow-up processing into a promise .then() which is fairly horrible and hard to follow.
Of course, the outer function keeps going and doesn't wait - but in this case, that is fine as everything will be complete before the instance setup completes.
I'm trying to dig myself out of a different hole I created when I set up uibuilder's templating system.
I allowed for external templates but I didn't allow for a "standard" template to be external, only internal. Over time that has come back to haunt me as some of the templates are examples of using front-end frameworks.
As we know, FE frameworks drift over time and now, trying to maintain them within the uibuilder module has become increasingly burdensome. So I want to dump them out but I still want to have a list people can refer to.
That means firstly - simplifying the template setup. Then adapting the setup function. It has to be async because the external part relies on degit which is purely async.
Once I can do this, I can easily update the more complex templates and have even more readily available showing more complex examples and including more integrated build tools and the like.
All of my nodes follow the same format. The 2nd parameter of RED.nodes.registerType references a function and it is that function that I wanted to make async. But if I try, the node won't load. It is that function that is run when an instance of your node is deployed in a flow.
I've worked around the issue by using an IIFE wrapped around an async section because I didn't actually need the whole fn to be async in the end.
Every instance of a node MUST have its own settings and processing separate from every other node. Behind that independent instance process you have a common set of data and processes.
If you don't have an equivalent of what I call nodeInstance but many nodes have as an embedded function (which really isn't good practice), you can never have more than one set of settings shared between all instances of a node type.