I have a class that populates a Map from a Flux source. I want to able to updateTheData() on the fly, but I want getTheData() to be able to return a Mono that resolves to current or pending data.
Basically if theData != null and no in progress flux, return Mono.just(theData) Otherwise return mono that will eventually emit theData.
Edit: This is the best I can do so far
class SomeClass {
private Mono<Map<String, Data>> theData;
private final SomeFluxService someFluxService = new SomeFluxService();
public SomeClass() {
updateTheData();
}
public void updateTheData() {
someFluxService.get()
.collectMap(Data::getId, Function.identity())
.subscribe(d -> this.theData = Mono.just(d));
}
public Mono<Map<String, Data>> getTheData() {
return this.theData;
}
}
But there is still the problem of before updateTheData() completes for the first time, getTheData() will return null
Help appreciated!