teavm icon indicating copy to clipboard operation
teavm copied to clipboard

Handling a JS function that returns a Promise

Open XomaDev opened this issue 6 months ago • 3 comments

Hello, thanks again for TeaVM. From past few hours, I'm trying to figure out a situation where my Java program immediately expects a value (from the JS). I learnt that TeaVM dosent support sleep() function. I did what I can after looking into the docs, such as:

@Async
public static native String stdInput();

private static void stdInput(AsyncCallback<String> callback) {
  stdInputAsync(callback::complete);
}
...
@SuppressWarnings("unused")
@JSFunctor
interface ICallback extends JSObject {
  void complete(String result);
}

My JS side code:

function stdInput(callback: (result: string) => void): void {
  callback("meow");
}

But it results in this error:

image

If I simply try to return a promise in stdInput(), I get an empty String at the Java side. Please help.

XomaDev avatar Aug 22 '24 16:08 XomaDev