Non blocking interop with JVM like Deffered.await()

In Java you must use callbacks to write async non-blocking code.

Try CompletableFuture.thenAccept instead of calling get. The supplied callback will run when the task completes without blocking any threads. You can control the callback thread with thenAcceptAsync. The code that uses the result goes in the callback not after the call to thenAccept, which will return immediately without waiting.

I suggest referring to guide, here’s an example : Java CompletableFuture Tutorial with Examples

1 Like