awaitas well as
then, with the following signature:
interopPromise is a Java object instance of the following class:
interopPromise object depending on the result of the Java
computeSomething() method call.
Promise object. A nice consequence of this property is that they can be used from an
Promise object instances. Therefore, it is possible for Java applications to interact with such objects by means of the
When executed, the code in the example will call the
Promise object with resolution value
42. As a result of the promise resolution mechanism, a Java
Consumer lambda function will be invoked and will print
Let’s look at an example: a polyglot Helidon Web application. The following figure provides an high-level overview of the main polyglot interactions in the example application we’ll use for this demo:
#1. Requests handling (Java): an HTTP Helidon Web server handles an incoming request. It parses the request URL and extracts any useful information such as a request ID. At this point, Helidon might already be using multiple parallel threads to handle concurrent requests.
await), delegating to another Java thread some heavy computation.
#3.Request processing (Java): In another thread, a Java method performs some CPU-intensive computation. Once done, it resumes the
async function can use
JSON.stringify() to create a response object that contains data computed in Java.
async function returns. The execution flow goes back to Java, where a
await to wait for asynchronous computations being performed in parallel.