MarkusJx / node-java-bridge

A bridge between Node.js and Java
https://markusjx.github.io/node-java-bridge/
MIT License
112 stars 6 forks source link

fix: avoid deadlock when calling proxy methods synchronously #58

Closed MarkusJx closed 1 year ago

MarkusJx commented 1 year ago

Allows proxies to be used in a synchronous context:

java.config.runEventLoopWhenInterfaceProxyIsActive = true;
const proxy = java.newProxy('java.util.function.Function', {
  apply: (arg: string): string => arg.toUpperCase();
});

const JavaString = java.importClass('java.lang.String');
const str = new JString('hello');

const res = str.transformSync(proxy);
// prints 'HELLO'
console.log(res);

This is done by forcing the event loop to run while waiting for the java process to return a result.