Please help me with reactor I need to check one condition max n times and return the final result after all
I found that reactor has reactor-extra module
https://projectreactor.io/docs/extra/snapshot/api/reactor/retry/Repeat.html
It has construction
Repeat.create(java.util.function.Predicate<? super RepeatContext<T>> predicate, long n)
Repeat function that repeats n times, only if the predicate returns true.
It looks like right solution, but I can't understand where should be
tha action, which I want to repeat?
I have Flux with many actions, but I want to repeat only one
Please make an example of code
Thank you
private int culculateNextResult(some params) {
// some implementation
}
private Boolean compareResults(int prevRes, int nextRes) {
// some implementation
}
public Flux<Boolean> run(some params, Flux<Integer> prevResults){
return prevResults.map(elem -> compareResults(elem, culculateNextResult(some params)));
// THIS LOGIC SHOULD BE REPEATED N times if compareResults(elem,
// culculateNextResult(some params))) == false, if true, we don't need
// to repeat
}
I want to repeat compareResults(elem, culculateNextResult(some params))) until it's nit true. but n times maximum and return Flux as a result