Return a Promise from a ScriptMethod

Hi,

I would like to return a Promise from a ScriptClass’ ScriptMethod. Is that possible?

Hi,

There is no automated way of doing this, as you have with NativeModule. The reason is that in ScriptClass callbacks you are not neccessarily running on the JS thread and can not run JS code or create JS objects.

However, if you use ExecutionThread.JavaScript, you can call into JS code that creates the promise for you. All UX nodes have a .ScriptContext variable (if cast to IScriptObject) through which you can execute JS code from string.

We have an internal issue to improve the ScriptClass interop features, but unfortunately its not top priority at this time.

What I want is to have code in my JavaScript execute after figuring something out in UX, which need to be async. Is there any smooth way to acheive such a callback today?

Right now my code is really ugly with deep coupling of a NativeModule and a UX node, and some spaghetti to let them know about each other.

Your solution sounds like the best we can do at the moment. As I mentioned above we have a planned task to improve the interop layer.

Hi,

.ScriptContext on Node is internal. From what you write it looks like you intend for this to be public

I think you can cast this to IScriptObject and access it from there?