I am very new to reactive programming in Spring WebFlux. Kindly excuse me for my ignorance here.
The below code is not adding the object EyeCare to the Flux eyeCares.
I read about Flux.create
, Flux.generate
here that seem to be used to create Flux also I read this
private Flux<EyeCare> populateFakeData(Locale locale, int count){
Flux<EyeCare> eyeCares = Flux.empty();
for(int i=0; i< count; i++){
eyeCares.concatWithValues(fakeDataService.generateEyeCare(locale));
}
return eyeCares;
}
Flux.create
or Flux.generate
the way I need to take to solve this?Flux.create
or Flux.generate
instead of eyeCares.concatWithValues
?You should be able to use Flux::generate
pretty easily.
private Flux<EyeCare> populateFakeData(Locale locale, int count){
return Flux.generate(()->new AtomicInteger(count), (state, sink) -> {
if (state.getAndDecrement() > 0 ) {
sink.next(generateEyeCare(locale));
} else {
sink.complete();
}
return state;
});
}