Bernhard
07/06/2026, 12:45 PMCLOVIS
07/06/2026, 1:50 PMsuspend function, so you will need a 'bridge' method on the Kotlin side.
In Kotlin, you can use future { …your code… } to create a CompletableFuture that a Java virtual thread can block on.Bernhard
07/06/2026, 1:51 PMWout Werkman
07/08/2026, 4:27 PMfuture too eagerly. The main purpose of both kotlinx.coroutines as well as virtual threads, is to get rid of asynchronous functions (AKA, a function that schedules work, and returns before that work might be done).
And future is one such example.
It's slightly better than your usual asynchronous functions because it takes a CoroutineScope, but it's not as nice as structured concurrency.
The problems with using this pattern is that:
• If your vthread gets canceled, the future doesn't get canceled by default.
• Your `ScopedValue`s aren't passed down to the underlying coroutine.
• It's unclear from the outside where exceptions go if you don't await the result.
• It's unclear where the CoroutineContext comes from.
These are answers that structured concurrency answers.
Ideally, you could simply use runBlocking, which answers 3/4 questions. However, it sadly also has serious footguns, but it probably has less footguns than not using structured concurrency at all with `future`s.
I just think that this nuance is important when giving recommendations on this topic.Vivek Modi
07/08/2026, 4:48 PMsuspend or use runBlocking. I was looking at CompletableFuture, but based on your concerns around structured concurrency, what would you recommend for this kind of Java-to-suspend bridge?Wout Werkman
07/08/2026, 5:30 PMfuture or launch depending on whether you want to process the result in Java.