Suppose I have this method:
public static Mono<String> getData2() {
return Mono.just("7");
}
I want to call this method, get back the string, convert that string to an Integer 7, and then return that integer in a non-blocking way. How can I do this?
I've tried this, but the map
function is blocking (synchronous):
public static Mono<Integer> getData1() {
return getData2().map(data -> Integer.parseInt(data));
}
I tried using flatMap
instead (asynchronous):
public static Mono<Integer> getData1() {
return getData2().flatMap(data -> Integer.parseInt(data));
}
But then I get this error: Type mismatch: cannot convert from int to Mono<? extends Integer>
So what can I do?