2
votes

I have legacy code which returns convert java.util.concurrent.Future, now I am supposed to wrap this method call in a layer which returns reactor publishers Mono or Flux. I believe approach to convert to either of them should be similar so what is the correct way to convert it to Mono.

Suppose for example I am getting Future from API and I need Mono

1
I am kind of beginner in this area so any help is greatly appreciated - dvsakgec
this is possible but requires a dedicated thread. That is, the main goal of using Mono/Flux, memory economy, would not be achieved anyway. - Alexei Kaigorodov
This is analogous to transforming a Future to a CompleteableFuture as described here - since a future has no concept of a "callback" when done, you have to block a thread. It's certainly not pretty, but alas there's no sensible way. stackoverflow.com/questions/23301598/… - Michael Berry

1 Answers

-2
votes

You can use Future::get as supplier in Mono::fromSupplier. Like this, Mono.fromSupplier(Future::get).